aspose file tools*
The moose likes JDBC and the fly likes Help with empty result set! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Help with empty result set!" Watch "Help with empty result set!" New topic
Author

Help with empty result set!

Nina Wang
Greenhorn

Joined: Jun 26, 2002
Posts: 11
There,
I am trying to call an Oracle 8.1.6 through EJB. But when I got an Empty ResultSet, it seems that the resultSet.next() always returns true. But if I then call method like resultSet.getInt(1), it will give me SQLException: java.sql.SQLException: java.lang.StringIndexOutOfBoundsException - String index out of range: 0.
How should I deal with this? Thanks in advance!!
The code is like:

nina
Kevin Mukhar
Ranch Hand

Joined: Nov 28, 2000
Posts: 83
You are misunderstanding something. First, if the ResultSet returns no rows, then next() will NEVER return a true value. Thus, if next() is returning true, there must be at least one row of data in the ResultSet.
Second, rs.getInt(1) is returning an int value, thus there is no way that the StringIndexOutOfBoundsException is occuring on that line of code. If you are getting a StringIndexOutOfBoundsException, then there must be some place in your code where you are attempting to use a String object and calling a method that indexes into the String (for example, charAt, indexOf, substring).
Please post the line number from the stack trace and the correct line of code which is causing the problem.
[ November 18, 2002: Message edited by: Kevin Mukhar ]
[ November 22, 2002: Message edited by: Kevin Mukhar ]
Nina Wang
Greenhorn

Joined: Jun 26, 2002
Posts: 11
Hi, Kevin,
Thanks for your reply!
I know the the resultSet.next() should return false if there is no record. But I did use Toad to check it, and the Toad says: No rows returned. But my code will always return true.
Such as for code as following:

Do you know what is the problem?
Thanks,
Nina
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Nina, as stated earlier, rs.next() will return false if there are no records. Oracle strictly follows the JDBC specs, so your code will work fine the way you have it. Read the rest of the stack trace on the error, it well tell you exactly which line is throwing the exception. When you find that, you will find that the JDBC code is most likely not the culprit, but some other java code. If it was the JDBC code, you would get a SQLException. If you need help reading the stack trace, post the full trace here and we'll tell you which line number is causing the java.lang.Exception.
Jamie
Nina Wang
Greenhorn

Joined: Jun 26, 2002
Posts: 11
Hi, There,
I just got a chance to check my code again. Still my problem is that even the ResultSet is empty (I checked with SQLPlus and Toad), the resultSet.next() will return true. (I know this doesn't make sense, but it is happening here, () But then if I try to call some method like getInt(1), the error it throws me at the weblogic server side is:
The error of Resultset is : java.sql.SQLException: java.lang.StringIndexOutOfBoundsException - String index out of range: 0
But this is no line indicator on the exception.
I am using the type II JDriver come with the Weblogic trial version, and obtain the connection from predefined DataSource at Weblogic server.
I really couldn't figure this out. Hope you guys can help me! Thanks!
Nina
Nina Wang
Greenhorn

Joined: Jun 26, 2002
Posts: 11
Hi, There,
My problem is fixed. The reason is the JDBC driver. I update the Oracle to 8.1.7 and update the weblogic JDriver to support that. The result returns to normal now.
I don't know why. But it was happening on my Win 2000. I am posting this so that if any one meets the same problem, this maybe of help, .
Many friends on this forum helped me to find the solution. Thanks, you guys!
Nina
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

I'm glad you got it working! I was just coming back here to say that if the JDBC driver didn't even follow the most basic of JDBC specifications, that maybe you need to think about a new driver!
Not needed now though! Thanks for posting your findings, I'm sure you'll save someone else a fewer headaches and time that it cost you
Jamie
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Help with empty result set!