Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ResultSet Empty

 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the Statements class defined and what is TOTAL_USERS?
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How is the database object USERS defined? Is it in a different schema to the user your Java connection is using?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved, many thanks. It was the config file which was wrong, also the i++

Regards
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What was the config file issue Angus?
 
Isaac Ferguson
Ranch Hand
Posts: 922
2
Java Netbeans IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I wasn't pointing well in the web.xml. I was pointing to localhost but my DB is in another server

Many Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic