aspose file tools*
The moose likes JDBC 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
Bookmark "No Exception for ResultSet TYPE_FORWARD_ONLY" Watch "No Exception for ResultSet TYPE_FORWARD_ONLY" New topic
Author

No Exception for ResultSet TYPE_FORWARD_ONLY

Rahul Shinde
Greenhorn

Joined: Jan 29, 2002
Posts: 9
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
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

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
Greenhorn

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

ResultSet.java says
int TYPE_FORWARD_ONLY = 1003;

Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

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: http://aspose.com/file-tools
 
subject: No Exception for ResultSet TYPE_FORWARD_ONLY