aspose file tools*
The moose likes JDBC and the fly likes rs.next() always return true even no result is querried Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "rs.next() always return true even no result is querried" Watch "rs.next() always return true even no result is querried" New topic
Author

rs.next() always return true even no result is querried

Ryan Webb
Greenhorn

Joined: Dec 09, 2009
Posts: 28
howdy Ranchers!

I have weird behaviors from resultset -> it always returns true!

I have this basic SQL statement:
I use this to check if there is existing records on the table. If not Existing, then I should insert a new records else
I only just to update the current shipment_no..



What's also weird is, when I breakpoint each step, It is working fine...when run RS.NEXT() IS ALWAYS TRUE! wtf!!!

Any advice?
Ryan Webb


frustrated to learn c/c++/objective-c
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
If you print the contents of the result set to the main output, what do you get?
Ryan Webb
Greenhorn

Joined: Dec 09, 2009
Posts: 28
Edwin Dalorzo wrote:If you print the contents of the result set to the main output, what do you get?


Hi Edwin Dalorzo,

I tried to get results (rs.getString(1), etc) I got SQLException...(w/c i think it means no result to get)

I also tried using SELECT COUNT(*) stuff and if rs.getInt(1) == 0 then shipment is not existing.
The select count(*) always returns a non-zero value...

I check the SQL query in Toad and there's no such shipment number...I think there's a ghost in DB..

This is the first time I encountered this...and man, it freaks me out...I even checked my old notes, and codes from previous projects, my code should be working....this is giving me headache!

Ryan Webb
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Hi Ryan!

May I ask what database and what drivers are we talking about here?

I just tried a similar scenario with a simple Derby database and it worked as expected. I daresay this could be a bug on the driver, but I would like to make sure before I affirm it.

If you print your sqlString once properly built with your variables, what do you get?
Ryan Webb
Greenhorn

Joined: Dec 09, 2009
Posts: 28
hi!

Im using Oracle DB using Oracle12_g.jar as jdbc driver on my localhost (im not sure in production server).

Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
PL/SQL Release 9.2.0.6.0 - Production
"CORE 9.2.0.6.0 Production"
TNS for HPUX: Version 9.2.0.6.0 - Production
NLSRTL Version 9.2.0.6.0 - Production

as well as you do, I'm very sure the java code works...I cross checked it using other tables and results are as expected. Only that particular table is problematic...

I printed to console the SQL query generated by java debugger and used it to query on TOAD sql editor, and works fine...as expected

I need a solution fast for this since im on tight schedule...but I will continue to solve this for future reference and for this forums reference as well to help other which might encounter the same problem in future and hopefully solve it.

Here's my quick fix for this wierd table for everyone's info
Anyway I filed for table change...apparently my suggested work around for this it for the table to have a primary key (I noticed no primary key in table) ...Then if I violate PK constraint, Java will throw sqlexception then handle it accordingly, I will update if exception will match the vendor's error code.

Thanks very much
Ryan Webb
Philippines
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: rs.next() always return true even no result is querried
 
Similar Threads
isNew() method
Result set type
total number of rows in ResultSet
closing Statement vs re-using it
SQL query takes too long to execute?