Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PostGreSQL resultset.next()

 
Adrien Ruffie
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic