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 the fly likes JDBC Drivers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Drivers" Watch "JDBC Drivers" New topic
Author

JDBC Drivers

jack nick
Ranch Hand

Joined: Jan 11, 2001
Posts: 96
Hi there,
I am using mysql on linux for my database using third party mm drivers. Basically the problem arised working with different version of the drivers.
An older version always pointed to the first record of the result set whereas the new version always points to the a position before the first record.
Situation where the resultset would return only one record can get tricky (like a count query).
At the moment I rectify this by catching the exception and assigning a concerned variable in the catch block.
Is there a better way to do this.
Bye
Jack
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
I'll start by assuming you have a proper Statement which I'll call 'stmt', and a query contained in a String I'll call 'query'.

If your ResultSet contains nothing it will skip over the 'while' block, if your ResultSet contains one or more results the 'while' block will execute. This will work regardless of database or driver.
Jason Menard
Jason Kilgrow
Ranch Hand

Joined: May 21, 2001
Posts: 47
Wow...that's really odd. I would think that they should work the same way.
According to standards, the pointer should always start before the first record in the resultset and it takes a rs.next() to move it to the "next" record which is, in the first place, the first record.
Are you certain that you are seeing the effect you spoke of? Is there any way that you could be mistaken in your debugging?
I'm not trying to be a smart alec. It's just that I've been "certain" before and it turns out that I'm wrong and not the code.
===============================================================
Originally posted by jack nick:
Hi there,
I am using mysql on linux for my database using third party mm drivers. Basically the problem arised working with different version of the drivers.
An older version always pointed to the first record of the result set whereas the new version always points to the a position before the first record.
Situation where the resultset would return only one record can get tricky (like a count query).
At the moment I rectify this by catching the exception and assigning a concerned variable in the catch block.
Is there a better way to do this.
Bye
Jack

jack nick
Ranch Hand

Joined: Jan 11, 2001
Posts: 96
Hi Jason,
Thanks, this solution is definitely one of the very obvious things that one skips looking around the world for solving a problem. Now I really feel silly not to have look just some lines below my errorneous code to get my answer.
Bye
Jack

jack nick
Ranch Hand

Joined: Jan 11, 2001
Posts: 96
Originally posted by Jason Kilgrow:
Wow...that's really odd. I would think that they should work the same way.
According to standards, the pointer should always start before the first record in the resultset and it takes a rs.next() to move it to the "next" record which is, in the first place, the first record.
===============================================================

You really got me thinking for a moment whether i could have been wrong. But no, I did check this out again and the error did occur. Also I sent a whole program on the assumtion that the standard stated the point is always to before the first record of the result set and had to bear some brunt because of the reported error as the testing team was using another version of the driver. Things there could have been some bug in the driver.
Drivers in concern are mm drivers for mysql.
mm.mysql.jdbc-1.2b points before the first
mm.mysql.jdbc-1.2 pionts at the first.
Bye
Jack
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Drivers