Exception Generated When Updating Table - Java
The following code works - the table is updated (confirmed on the SQL server by looking at the table contents before and after the code is executed). But, when I run the program in
Solution 1:
The function "stmt.executeUpdate(SQLquery);" returns an Integer, because you are not retrieving any data from the database. Try this:
Integer c = stmt.executeUpdate(SQLquery);
The Integer value indicates how many rows have been changed.
Solution 2:
Take a look at the javadocs for PreparedStatement for JRE that you're using. PreparedStatement.executeUpdate() returns an int of the number of rows that were updated. Here is a link to the PreparedStatement docs.
Solution 3:
The executeUpdate returns an int, and not a resultset. http://docs.oracle.com/javase/1.4.2/docs/api/java/sql/Statement.html#executeUpdate(java.lang.String)
int nbUpdatedResult = stmt.executeUpdate(SQLquery);
Solution 4:
The executeUpdate method returns number of rows affected, that's why you have this error.
So it's good to use this method. But you won't retrieve edited values.
Post a Comment for "Exception Generated When Updating Table - Java"