• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

executeUpdate with ResultSet - Incompatible type for declaration.

 
Annemarie McKeown
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am executing the following code to update a record in a database table to a new value, but im having a problem with using a ResultSet and an executeUpdate statement together:

The error im getting in the browser says -
Incompatible type for declaration. Can't convert int to java.sql.ResultSet.
Does anyone know how to fix this?
 
Gowrishankar Mudaliar
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
executeUpdate returns an int signifying no. of rows updated. which is alright.
So, replace resultset with an int variable.
To get a result set, you should run a select query in executeQuery method.
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a general rule, you only use "executeQuery(...)" when you have a SELECT query. If you do a INSERT, UPDATE or DELETE you use "executeUpdate(...)". If you don't know what type of query it is--for example if it's a query that is passed in by the user--you can use "execute(...)". The return values are "ResultSet", "int" and "boolean", respectively.
Some database drivers will let you get by with doing an "executeQuery(...)" with an INSERT, UPDATE or DELETE, but it's best to choose the correct method for each query.
Also, there is no need to do a ".newInstance()" on the "Class.forName(...)". It's bad practice and will result in an unnecessary and useless instance being created.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic