executeUpdate with ResultSet - Incompatible type for declaration.
Joined: Nov 07, 2003
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?
Joined: Oct 20, 2001
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
Joined: Sep 03, 2003
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.