• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help debug this program

 
nash avin
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The database table has got 2 fields "username" and "password".The code for accessing the database is given below


If I pass the values that are present in the database table into userpresent.validateUser("z","x") ,then I am getting the ok message .
If I give a value that is not present in the database table then also I get the ok message .
Kindly let me know what the problem could be.
Help would be appreciated.
Thanks
AS
 
Lu Battist
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your program is truely printing the message "ok" then I don't know. But if the userValidatin method is just returning true instead of false you need look no further than your initilization: boolean retval = true;
Follow the logic through, the if-else statement is useless (The validation is done as part of the query). The else part is unreachable.
Also, while your prepared statement will work as is. You should check out the JDBC tutorial to learn how take advantage of their benefits. It would save you having to single quote strings for one.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34656
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nash,
In addition to what Lu said, you are not checking the username/password if the user is not in the database. Since the rs.next() returns false, the username and password variables keep the values they had when they were initialized. Since these are the values the user passed in, the if statement will always return true. (You are comparing what the user passed in to what the user passed in.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic