This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes Please help debug this program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Please help debug this program" Watch "Please help debug this program" New topic
Author

Please help debug this program

nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
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

Joined: Feb 17, 2003
Posts: 104
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

Joined: May 26, 2003
Posts: 30585
    
154

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.)


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
GeeCON Prague 2014
 
subject: Please help debug this program