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