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 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 and Relational Databases
Bookmark "records not showing in ResultSet" Watch "records not showing in ResultSet" New topic

records not showing in ResultSet

Vaishali Paramane
Ranch Hand

Joined: Mar 05, 2007
Posts: 107

Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from user_data");
int in=0;

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

Preparing for SCWCD
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3753

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?

[OCA 8 Book] [Blog]
Vaishali Paramane
Ranch Hand

Joined: Mar 05, 2007
Posts: 107
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: 1141

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,
Vaishali Paramane
Ranch Hand

Joined: Mar 05, 2007
Posts: 107
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;
you shoud put after incrementation only you get the count earlier you put before incrementation ok..

you got it .....

Swastik Dey

Joined: Jan 08, 2009
Posts: 1584

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

Joined: Mar 05, 2007
Posts: 107
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:
subject: records not showing in ResultSet
It's not a secret anymore!