File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Head First Android this week in the Android forum!
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
Author

No Exception for ResultSet TYPE_FORWARD_ONLY

Rahul Shinde
Greenhorn

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
Sheriff

Joined: Oct 14, 2005
Posts: 19687
    
  10

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: 11
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: 3717
    
  61

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
 
It's not a secret anymore!