aspose file tools*
The moose likes JDBC and the fly likes Result set is empty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Result set is empty" Watch "Result set is empty" New topic
Author

Result set is empty

sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137


I have checked in Sqlplus there are two entries in the table login. It does not go into the loop while(rs.next());

How do I fix this so it works?

Thanks,

Sonia
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
If you do this, what do you get?

sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
I cannot do that. I have to use the connection and stmt to execute a query to the database.

THanks,

SOnia
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
"System.out.println" has nothing to do with the DB - it serves as a debugging aid. The point Edwin was trying to make is that you should check what the actual query looks like that gets sent to the DB.

As a side note, it is much better to use a PreparedStatement than to construct the query on the fly using string concatenation. Amongst other benefits, it makes sure that the code isn't susceptible to SQL injection attacks.


Ping & DNS - updated with new look and Ping home screen widget
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
The examples on prepared statements are not that complete.



Is this good? The print statement for the query gives me the following without a semicolon:

and n=0;

Thanks in advance,

Sonia
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39578
    
  27
What happens if you run that query directly against the DB? Are you getting results returned?
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
yes; i get results.

Sonia
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9343
    
111

In your code are you sure you are connecting to the same database which contains these records?

[My Blog] [JavaRanch Journal]
sonia pandit
Ranch Hand

Joined: Apr 19, 2008
Posts: 137
It was a matter of case. I changed the column to uppercase and it works. I did not realize SQL was case sensitive.
I also changed it to use Prepared Statement. Now somebody has adviced me to use Hibernate and Spring. So I have to research that. Sure I will be posting questions with that.

Thanks,

Sonia
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Result set is empty
 
Similar Threads
kindly help me in redirecting....... as soon as possible
Validating Username and Password in JSP
Not able to navigate the user to another jsp in servlets using RequestDispatcher
unable to forward using jsp:forward
Retrieving & Comparing data from database