5 messages in com.mysql.lists.javaRe: rs.next() problems with mm.mysql/...
FromSent OnAttachments
Cato, Christopher12 Feb 2001 07:04 
Le, Paul12 Feb 2001 07:43 
Cris Perdue12 Feb 2001 07:59 
Tim Endres12 Feb 2001 09:26 
Cato, Christopher13 Feb 2001 00:24 
Subject:Re: rs.next() problems with mm.mysql/JDBC 2
From:Tim Endres (Tim.@SecureByDesign.com)
Date:02/12/2001 09:26:32 AM
List:com.mysql.lists.java

First, I presume you meant to say executeQuery(), since execute() does not return a ResultSet.

Second, the documentation is very clear for ResultSet. Your original code should have never worked in the first place. A call to next() is required to position to the first row. If the MM driver allowed this to work, then that was a poor design choice for MM.

Finally, if you do not want to correct all of your code, then I would recommend that you go back to the older MM driver that provided you with the broken behavior, until you have time to fix your code.

Also, I agree with Cris that "if ( rs.next() ) { ... } else { ... }" is a better construct when you expect a one row result.

tim.

In my code, there are quite a number of spots where I directly read a one-row response like follows:

--------------------------------------------------- ResultSet rs = stmt.execute(sql);

String userId = rs.getString("userid"); String status = rs.getString("accountStatus");

----------------------------------------------------

Now, this won't work anymore because there is now a position 'before' and 'after' the result set implemented in the new mm.mysql driver.

Does anyone have any idea how I could fix this without having to rewrite all of my applications? Or do I really have to put ALL these within while(rs.next()){} loops?

I put them inside if (rs.next()) conditionals, though I'm sure that's not what you are looking for. Or outside if (!rs.next()) conditionals. It does give one a chance to check the corner cases.

-Cris