aspose file tools*
The moose likes JDBC and the fly likes records not showing in ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "records not showing in ResultSet" Watch "records not showing in ResultSet" New topic
Author

records not showing in ResultSet

Vaishali Paramane
Ranch Hand

Joined: Mar 05, 2007
Posts: 106


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


SCJP, SCJD
Preparing for SCWCD
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3706
    
    5

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?


My Blog: Down Home Country Coding with Scott Selikoff
Vaishali Paramane
Ranch Hand

Joined: Mar 05, 2007
Posts: 106
I am using myEclipse and oracle. It is not giving any error but I am not getting any records
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1132

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

Joined: Mar 05, 2007
Posts: 106
After shutdown my laptop that code started working . Don't know error but program working.

thanks to help me
sudheer yathagiri kumar
Ranch Hand

Joined: Mar 22, 2011
Posts: 35
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

Joined: Jan 08, 2009
Posts: 1477
    
    6

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.


Swastik
Vaishali Paramane
Ranch Hand

Joined: Mar 05, 2007
Posts: 106
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: records not showing in ResultSet