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 My sql query returns zero rows 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 "My sql query returns zero rows" Watch "My sql query returns zero rows" New topic

My sql query returns zero rows

Revanth Sharma

Joined: Jul 30, 2011
Posts: 14

I have written a servlet code for checking if the username is already exists in the database for registering, however my sql query returns zero rows. I have no idea of what is happening in the query.

rs.getRow() returns value zero though there are 2 records in the database with the username I have given. I wanted to print the sql query to check if the query is working properly, i do not understand how to print the query because of the prepared statement. is there a possible way to print the sql query ?

thanks in advance!!
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

That code doesn't tell you anything about what the query returns. In fact all it does is to run the query, ignore the data, and ask "What is the current row?"

And since you haven't tried to read anything from the query, the current row is naturally zero.

Any tutorial I have ever seen on JDBC shows you how to read through a ResultSet using the method. I would suggest you have a look at some JDBC tutorials.

(By the way: there is nothing special about servlets. So the fact that you have problems with JDBC code doesn't make this a servlets problem just because you happened to put the code in a servlet. I'm going to move the post to the JDBC forum, since it's a question about JDBC.)
I agree. Here's the link:
subject: My sql query returns zero rows
It's not a secret anymore!