Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Statement.executeUpdate

843859Jan 24 2007 — edited Jan 24 2007
After creating a statement, one can recieve a resultSet by two means:
...
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
or
...
Statement stmt = conn.createStatement();
int rows = stmt.executeUpdate(sql);
ResultSet rs = stmt.getResultSet(sql);
I've always used the latter because it easily supplies me with the row count without having to go through rs.last() and rs.getRow() etc..
However, I only recently read the javaDoc for executeUpdate(), which claimed that the method should only be used for INSERT,UPDATE, or DELETE statements and would throw a SQLException if a ResultSet was produced. This, obviously, is false considering I've been using it for a while with SELECT statements.
Is this just an small error on Sun's part? Do the rest of you use executeUpdate() with SELECT statements also?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 21 2007
Added on Jan 24 2007
6 comments
570 views