File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes No Exception for ResultSet TYPE_FORWARD_ONLY Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "No Exception for ResultSet TYPE_FORWARD_ONLY" Watch "No Exception for ResultSet TYPE_FORWARD_ONLY" New topic

No Exception for ResultSet TYPE_FORWARD_ONLY

Rahul Shinde

Joined: Jan 29, 2002
Posts: 11
Here is my code example. I am expecting an exception that indicates that the ResultSet is TYPE_FORWARD_ONLY but I get none. I am using MySQL DB with Type 4 Driver.
Right now I get the contents of the contacts table printed twice with no exceptions.
JavaDoc says
Statement createStatement() throws SQLException
Result sets created using the returned Statement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY.

What am I missing here?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Have you examined the ResultSet to see what its type actually is? I haven't looked, but I expect there must be a method which you can call to find out.
Rahul Shinde

Joined: Jan 29, 2002
Posts: 11
I added the getType() method on the ResultSet to print that.
It says "Type = 1003" says

Martin Vajsar

Joined: Aug 22, 2010
Posts: 3733

I'd say that the resultset type determines the minimum capabilities of the resultset. In this case, the authors of the JDBC driver probably saved themselves some work by not implementing the forward only type, and used the more capable one instead. In correctly coded applications this shouldn't lead to problems. You might get a problem if you tested your application with a different JDBC driver than the one actually used in production (by not catching this bug in test and having it appear only in production, for example) - however, it is always advisable to match the test environment as closely to the production environment as possible.
I agree. Here's the link:
subject: No Exception for ResultSet TYPE_FORWARD_ONLY
It's not a secret anymore!