File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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
Reply locked New topic
Author

my resultset return what????

alex han
Ranch Hand

Joined: Dec 13, 2002
Posts: 46
i use while(rs.next()) to get data from a table named "xx" in oracle,
code is :
int j=0;
while (rs.next())
{
j=rs.getint(1)+1;
System.out.println(rs.getint(1))
}
someone told me that if there are no record in table "xx",rs.next() 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 rs.next() 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 rs.next() 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.
Jamie
Cobras9
Greenhorn

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
Rancher

Joined: Mar 06, 2001
Posts: 13459

Hmm, it appears that this thread is continued HERE
I'll close this one to prevent duplicate conversations.
Dave
 
GeeCON Prague 2014
 
subject: my resultset return what????