code: --------------------------------------------------------------- wire query="INSERT right into opr_rt_info worths (""+"?"+"",""+ "?"+"",""+"?"+"",""+"?"+"",""+"?" +"",""+"?"+"")"; System.out.println(query); pstmt = conn.prepareStatement(query); pstmt.setString(1,opr_name1); // exemption is thrown pstmt.setString(2,opr_mode1); pstmt.setString(3,rt_name1); pstmt.setString(4,rt_ch_no1); pstmt.setString(5,rt_ch_freq1); pstmt.setString(6,rt_selection_flag1); int res1=pstmt.executeUpdate(query); --------------------------------------------------------------------end java.sql.SQLException: Parameter index the end of range (1 > number of parameters, i m sorry is 0). exception is thrown on indict pstmt.setString(1,opr_name1); if anybody has solution then please help me out. Regards Sachindra


You are watching: Java.sql.sqlexception: parameter index out of range (1 > number of parameters, which is 0).

Bartender
*

*
*
*

posted 13 year ago
*
*

You space using a sql string favor this: INSERT right into opr_rt_info worths ("?","?","?","?","?","?") which will certainly insert six question marks into your table. If you want to use a PreparedStatement (which is a good thing) get rid of the quotes round the inquiry marks. < respectable 21, 2008: message edited by: Paul Sturrock >
posted 13 year ago


See more: 4Wd Transfer Case Position Sensor/Selector Switch, Genuine Navara D40 4Wd Drive Switch Transfer Case

I"m encountering the exact same problem. my java code: string sqlStatement="INSERT right into User worths (?,?,?,?,?,?)"; try if(ds!=null) con=giveConnection(ds); if(con!=null) pstmt = con.prepareStatement(sqlStatement); cable fname=registerForm.getFname().trim().toUpperCase(); string lname=registerForm.getLname(); if(!lname.equals(null)) lname=lname.trim().toUpperCase(); else lname=""; userExist = checkDuplicateUser(fname, con); if(userExist!=0) affectedRow = -1; else pstmt.setString(1, fname); pstmt.setString(2, lname); pstmt.setString(3, "user"); pstmt.setInt(4, 0); pstmt.setString(5, PasswordEncryptor.getInstance().encrypt(registerForm.getPassword())); pstmt.setString(6, registerForm.getEmail()); log.debug("sqlStatement: "+sqlStatement); affectedRow=pstmt.executeUpdate(); con.commit(); catch(SQLException sq) log.debug("inside sql exemption of add user"); sq.printStackTrace(); finally try pstmt.close(); con.close(); catch(SQLException sq) log.debug("inside sql exception of include user:2"); return affectedRow; } Server log: java.sql.SQLException: Parameter index the end of variety (1 > variety of parameters, which is 0). In ~ com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) in ~ com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) in ~ com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926) at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3326) in ~ com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3310) at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:4146) in ~ org.apache.commons.dbcp.DelegatingPreparedStatement.setString(DelegatingPreparedStatement.java:132) at com.onlinelibrary.dao.OnlineLibraryDAO.addUser(OnlineLibraryDAO.java:65) at com.onlinelibrary.action.RegisterLibraryAction.execute(RegisterLibraryAction.java:65) mysql table structure: mysql> desc user;+-------------+----------------------+------+-----+---------+-------+| field | kind | Null | crucial | Default | Extra |+-------------+----------------------+------+-----+---------+-------+| fname | varchar(20) | NO | PRI | | || lname | varchar(15) | yes | | NULL | || designation | enum("admin","user") | yes | | NULL | || concerns | smallint(5) unsigned | correctly | | NULL | || password | varchar(100) | yes | | NULL | || email | varchar(100) | correctly | | NULL | |+-------------+----------------------+------+-----+---------+-------+6 rows in collection (0.33 sec) I"m getting exemption at: pstmt.setString(1, fname); I"ve currently registered one user through this. However after that currently I"m acquiring this exception. have the right to somebody you re welcome help? Thanks