Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

my resultset return what????

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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"
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hmm, it appears that this thread is continued HERE
I'll close this one to prevent duplicate conversations.
Dave
 
    Bookmark Topic Watch Topic
  • New Topic