Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why executeQuery() doesnt work?  RSS feed

 
Nil. Hatamova
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi friends.
I want to create web page . In login page i want create sessions for users and admin. But i have error. My query doesnt give result. rslt.next() is not true

 
Dave Tolls
Ranch Foreman
Posts: 2996
37
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should not be in a JSP page.
At the least it should be in a servlet.

Log the SQL string used (you might want to move that into a separate SQL String variable).
That way you'll see what query is being run.

Also, that's not a PreparedStatement.
There's no binding of variables done in it.

Finally I would suggest giving the user a role, rather than checking the username.  You also don't need to recheck the password.  You already know it's correct.

Oh yes, just noticed, you're not closing your resources, either by using a try-with-resources, or in a finally block.
 
Stephan van Hulst
Saloon Keeper
Posts: 7927
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides the points that Dave made, I want to emphasize how important it is to use prepared statements correctly. Right now, you're putting user supplied information directly in your query.

Please explain to us what will happen if I pass the following uname in the request:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!