• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

records not showing in ResultSet

 
Vaishali Paramane
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from user_data");
int in=0;
while(rs.next()){
System.out.println(in);
in++;
}


connection is successful but I want to count record from user_data.
user_data has records but still I am not able to go inside while loop.

Thanks in advance
 
Scott Selikoff
author
Saloon Keeper
Posts: 4031
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What database software are you using? Some DBMS's record information by user. Other than that, the statement looks fine. Is it possible it's throwing an exception that's being caught?
 
Vaishali Paramane
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using myEclipse and oracle. It is not giving any error but I am not getting any records
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vaishali,
Methods "createStatement", "executeQuery" and "next" all throw "SQLException".
This is a checked exception which means your code must handle it.
As Scott implied in his reply to you, perhaps you are catching the "SQLException" but not doing anything with it?
I suggest you post your exception handling code as well.
If you are certain no exceptions are being thrown, then the only conclusion is that your query returns no rows.
In my experience, these are the only two reasons that the "while" loop in your code is not being executed.

Good Luck,
Avi.
 
Vaishali Paramane
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After shutdown my laptop that code started working . Don't know error but program working.

thanks to help me
 
sudheer yathagiri kumar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vaishali Paramane wrote:

HI vaishali,
1.get jdbc connection

2.i think you got problem in while loop na..
you have table shoud be created in data base.then only retriveing is posssible ok.
3 in your code you can not retrive any details regarding fields in the database table
see once..
int in=0;
while(rs.next()){
System.out.println(rs.getInt(1)+""+rs.getString(2)+""+rs.getInt(3));
in++;
System.out.println(in);
}
you shoud put after incrementation only you get the count earlier you put before incrementation ok..

you got it .....

 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you just wish to count the number of records, why not use select count(*). For example if you have 10,000 records, and you use a loop, it will execute 10,000 number of times just to count the number of records.
 
Vaishali Paramane
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did that also but that time it was not showing records though in the database table there was records.
I was checking is should go inside while loop then i can check query and inside while loop as my requirement.

Thanks for help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic