i have a question.
i have a standalone java swing program that i use with postgreSQL jdbc. it has a login page which can compare the textfield with the value in database.
this is part of my code:
problem is, when i entered the correct username and password, the "incorrect login and password" warning JOption still pops out!
can you tell me how to fix this? thank you in advance!
Generally speaking, selecting * from a table is a bad idea. Similarly getting a value from the resultset based on the index is a bad idea. There is the potential here that you are getting the wrong values. I strongly recommend you change that to (changing field names as appropriate):
Now if you were to enter "user-b/password-b" - what would happen on the very first loop through your code?
Alternatively, if you had entered "user-a/password-a", what would have happened on the second loop through your code? (Why do you allow a second loop through your code?)
Which goes back to what I was saying earlier - is your code that displays the "Incorrect login or password" in the right place? Is there a better way of determining whether any of the usernames/passwords matched before showing that?
String sql="Select * from login where username=? and password=?"
Swastik Dey wrote:
The above code it self will satisfy your purpose, then what is the below code. Why are you checking once again?
just by doing this your purpose should get solved, with an assumption that username and password forms a unique record
im doing that because i wanna compare if the user inputs the right set of username and password.
if i follow your suggestion, then how to compare the password part?