GeeCON Prague 2014*
The moose likes JDBC and the fly likes executeUpdate with ResultSet - Incompatible type for declaration. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "executeUpdate with ResultSet - Incompatible type for declaration." Watch "executeUpdate with ResultSet - Incompatible type for declaration." New topic
Author

executeUpdate with ResultSet - Incompatible type for declaration.

Annemarie McKeown
Ranch Hand

Joined: Nov 07, 2003
Posts: 47
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

Joined: Oct 20, 2001
Posts: 39
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

Joined: Sep 03, 2003
Posts: 399
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: executeUpdate with ResultSet - Incompatible type for declaration.