I am updating table using PreparedStatement
the following code works perfectly
pst = conn.prepareStatement("UPDATE playjdbc SET jlname ='javafx10new' WHERE jfname = 'java10'");
int i = pst.executeUpdate();
but when i tried like this it throwing exception
pst = conn.prepareStatement("UPDATE playjdbc SET jlname ='javafx10new' WHERE jfname =?");
pst.setString(2, "java10"); // yeah second column is jfname
int i = pst.executeUpdate();
stacktrace :
java.sql.SQLException: Invalid column index
at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:5330)
at oracle.jdbc.driver.OraclePreparedStatement.setString(OraclePreparedStatement.java:5318)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.setString(OraclePreparedStatementWrapper.java:282)
at com.indus.database.EmployeeDTO.updateData(EmployeeDTO.java:114)
2 in following refers to the position of the question mark in query string, not to the position of column in database table and not to the order of column names used in query:
pst.setString(2, "java10"); // yeah second column is jfname
Use 1 instead.
pst.setString(1, "java10"); // first question mark is jfname
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With