• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with empty result set!

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
crispy bacon. crispy tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic