wood burning stoves*
The moose likes JDBC and the fly likes PostGreSQL resultset.next() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "PostGreSQL resultset.next()" Watch "PostGreSQL resultset.next()" New topic
Author

PostGreSQL resultset.next()

Adrien Ruffie
Ranch Hand

Joined: Jan 14, 2009
Posts: 90
Hello all,

I have the following code:



My table PEOPLE is empty but why I call rs.next() with postgresql, this instruction return true and not false ... instead with Oracle, MSSQL, ... previous instruction return correctly false ...
I have try several JDBC driver of postgresql but nothing.

Any one have a idea ?

best regards,

Adrien


SCJP 5, SCDJWS 5
http://adrien-ruffie.blogspot.com
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

If it returns true, I'd suggest trying to access the fields in that row and see what happens. Chances are that the table is not empty after all.
Adrien Ruffie
Ranch Hand

Joined: Jan 14, 2009
Posts: 90
I actually tried to access the data and it give me an id: 0000000001 which doesn't exist ... this simply incremented the next() with the first generation of ID ...
very strange ... it's the default behavior ?
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

No, a SELECT statement should return the data as they exist in the database. Of course, there is still a possibility of a bug in the JDBC driver, but...

What I still think is that you're looking at another table which is empty, but in Java selecting from a different table which contains data. Are you using the same user in the JDBC code and whatever tool you use to look in the database? Couldn't there be a synonym, view or other thing which would cause the tables to be mixed up?

Besides, the table probably contains fields other than ID. Did you try to print out these? If they contain meaningful texts (names, for example), the table is probably real - it would be highly unlikely that a bug in a JDBC driver would cause some meaningful names and texts to appear out of nowhere.
Adrien Ruffie
Ranch Hand

Joined: Jan 14, 2009
Posts: 90
I found the problem, a mistake into db connection url:

jdbc:postgresql://postgres-server:5432:TestBase was use

I change to:
jdbc:postgresql://postgres-server:5432/TestBase

And I work correctly, but it's strange that JDBC driver doesn't throws
a exception with a bad url format ...
 
 
subject: PostGreSQL resultset.next()