Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

My sql query returns zero rows

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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!!
 
Marshal
Posts: 25443
65
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 rs.next() 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.)
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic