File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes my resultset return what???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Reply locked New topic

my resultset return what????

alex han
Ranch Hand

Joined: Dec 13, 2002
Posts: 46
i use while( to get data from a table named "xx" in oracle,
code is :
int j=0;
while (
someone told me that if there are no record in table "xx", return false,so j should equals 0 and System.out.println should not execute
but i find that even there are no record in table "1", j equals 1! and print 0 in tomcat's console
why?i believe if return false,j=rs.getint(1)+1 and System.out.println should not execute,but infact it execute.
is anybody can help me? thanks a lot
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

it depends on your query. If you use "select count(*) from ..." it will always return at least a 0. If in fact you have a "select column1, ... from XX ..." then will never be true when no matches are found in the database unless your driver your driver is not even close to being JDBC compliant. Also, verify using a SQL client that no results are returned for the exact query you are trying to execute in java. If you find that it is still not working properly, post the JDBC code ( including the SQL statement ) and identify the JDBC driver/database combo you are using so we can help you solve this problem.

Joined: Dec 20, 2002
Posts: 3
depending on different database, some db return false, some returns 0(like our db Informix)
becuase u asked for an Integer and it doesnt find a record in the database so it returns a "0" then u added 1 on so the System.out.println prints a "1"
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Hmm, it appears that this thread is continued HERE
I'll close this one to prevent duplicate conversations.
I agree. Here's the link:
subject: my resultset return what????
It's not a secret anymore!