Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet.TYPE_FORWARD_ONLY usage

 
Frank Rennie
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I got an error using the same code:



 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic