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 ResultSet Empty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ResultSet Empty" Watch "ResultSet Empty" New topic
Author

ResultSet Empty

Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 331
Hi,

I am trying to use a Resultset.

In my case I have this query:

Select * from users;

Using SQLYog it works perfectly ad gives me a lots of rows. Then in my code I have wrote;

query = Statements.TOTAL_USERS;

totalUsers = con.prepareStatement(query);
resultSet = totalUsers.executeQuery();

And the Resultset is empty.

Any tip, please?

Many Thanks,
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Where is the Statements class defined and what is TOTAL_USERS?
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 331

Imagine this code instead of the code in my original post.


query = Select * from users;

totalUsers = con.prepareStatement(query);
resultSet = totalUsers.executeQuery();
while (resultSet.next()) {cont=cont++}

Then cont is 0

Any tip, please?

Many Thanks,
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

How is the database object USERS defined? Is it in a different schema to the user your Java connection is using?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Angus Ferguson wrote:while (resultSet.next()) {cont=cont++}


I'm sure we've had thousands of threads about why "i = i++" doesn't do what you think it does. Let me track down the FAQ entry which must already exist... (still looking)...

Okay. Here it is: PostIncrementOperatorAndAssignment.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

Jeez Paul, I feel like an idiot for not spotting that! Great answer which means the result set is not empty but each time round the loop, the variable cont is always set to 0.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It's all in the framing of the question, isn't it? When you ask "Why is my result set empty?" that leads people to assume that the result set is empty, and start trying to explain why it's empty.
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 331
Solved, many thanks. It was the config file which was wrong, also the i++

Regards
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1012
    
    5

What was the config file issue Angus?
Isaac Ferguson
Ranch Hand

Joined: Jun 22, 2012
Posts: 331
Hi I wasn't pointing well in the web.xml. I was pointing to localhost but my DB is in another server

Many Thanks
 
Consider Paul's rocket mass heater.
 
subject: ResultSet Empty
 
Similar Threads
why is the List returning empty?
ResultSet return value for an empty query
Not getting resultSet from Prepared statement
my query is successfully running in database but it is returning empty resultset in my java program
How to get a row count