This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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.
 
Consider Paul's rocket mass heater.
 
subject: executeUpdate with ResultSet - Incompatible type for declaration.
 
Similar Threads
Starter Question.
2 conditions to be checked
update button
A Servlet executeUpdate question
incompatible types