aspose file tools*
The moose likes JDBC and the fly likes ResultSet.TYPE_FORWARD_ONLY usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet.TYPE_FORWARD_ONLY usage" Watch "ResultSet.TYPE_FORWARD_ONLY usage" New topic
Author

ResultSet.TYPE_FORWARD_ONLY usage

Frank Rennie
Greenhorn

Joined: Sep 18, 2013
Posts: 11
According to the spec, ResultSet.TYPE_FORWARD_ONLY means that you can only move the cursor forward through a result set.

In the code below, I create a statement and specify ResultSet.TYPE_FORWARD_ONLY. After executing the query, I position the cursor at the end of the ResultSet using afterLast() and then call previous() to try to move backwards. I'd expect the code to fail at this point as I've specified ResultSet.TYPE_FORWARD_ONLY.

However, the code runs successfully and prints the last row. Why didn't it fail?





Not sure if it's relevant, but I'm connecting to a local MySQL DB and running the script via Eclipse.
Steven Squeers
Ranch Hand

Joined: Aug 19, 2013
Posts: 62
Hi
I got an error using the same code:



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18986
    
    8

So... Oracle's driver implements the API correctly (the API says that calling afterLast on a forward-only ResultSet should throw an SQLException) and MySQL's doesn't. You might well consider that to be a bug on MySQL's part.
Frank Rennie
Greenhorn

Joined: Sep 18, 2013
Posts: 11
Thanks for your input guys. I'd assumed that I'd somehow misunderstood the spec.

When you're learning new stuff, it's natural to assume that you've got the wrong end of the stick rather than that the software itself is misbehaving.
Steven Squeers
Ranch Hand

Joined: Aug 19, 2013
Posts: 62
No worries. I'd have reacted in the same way; it's maddening when you find inconsistencies or contradictions!
Have you tried running it using the command line, btw? It shouldn't make any difference (I suppose; I have zero experience with Eclipse) but it would be good just to exclude the Eclipse side of things.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18986
    
    8

Frank Rennie wrote:When you're learning new stuff, it's natural to assume that you've got the wrong end of the stick rather than that the software itself is misbehaving.


That's right. And even when you're an experienced programmer you should still assume that it's your fault, rather than somebody else's fault, until proved otherwise. That's just a more practical way of solving problems.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

JDBC drivers are wild beasts. I've once hunted for a bug in a jTDS driver (yes, there is one too ) and looked at the source code. There were some comments which expressed the authors' uncertainty about what some particular method is exactly supposed to do.

The bug I've mentioned has taught me that it is not advisable to test an application using a JDBC driver/database different from the one the system will be run on. The JDBC drivers aren't born equal.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ResultSet.TYPE_FORWARD_ONLY usage