| Author |
authenticating website users with mysql dbase
|
Tontang Bei
Ranch Hand
Joined: Oct 21, 2006
Posts: 130
|
|
Im a newcomer to SQL. I have a web page where I am accepting a username and a password and then authenticating the user by checking if his username and password exists on the dbase. I am using the method below. but it alway returns false meaning that the username and password doesnt exists but in the Dbase I can clearly see that the particular user with the supplied username and password does exist. How can I rework or make changes in this code. What am I doing wrong?Thanks for all your help
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
Your query is this: Do you have any users with the username "username" and the password "password?
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Tontang Bei
Ranch Hand
Joined: Oct 21, 2006
Posts: 130
|
|
Ahhh...I see now..My mistake. thanks [ May 03, 2007: Message edited by: Tontang Bei ]
|
 |
Tontang Bei
Ranch Hand
Joined: Oct 21, 2006
Posts: 130
|
|
I have modified the code to have correct sql. But now the method wont return anything. no true no false. What am I doing wrong? Thanks
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
My assumption would be that it is throwning a SQLException instead, since that is pretty much the only way could possible return nothing. How do you call the method? Are you handling the possible exception or are you throwing it away?
|
 |
Jan Cumps
Bartender
Joined: Dec 20, 2006
Posts: 2343
|
|
WHERE UserName="+username+"&&"+"Password="+password;
Shouldn't that be: The result should look like this: Regards, Jan (have a look at PreparedStatement. It makes your code cleaner.) (and have a look at container managed security. Your server will have user authentication functionality on board.) [ May 03, 2007: Message edited by: Jan Cumps ]
|
OCUP UML fundamental
ITIL foundation
|
 |
Tontang Bei
Ranch Hand
Joined: Oct 21, 2006
Posts: 130
|
|
These were the exceptions I was getting This is the method I was using This is how I was calling it I got rid of all those exceptions by making the isMatch() method a NOn static. JDBC is proving to be a pain
|
 |
Jan Cumps
Bartender
Joined: Dec 20, 2006
Posts: 2343
|
|
JDBC is proving to be a pain
That error has nothing to do with JDBC. It's the code. My guess: You're using the static method isMatch(), which uses the static property connection. And you might not have connected to the database when calling static isMatch(...).
|
 |
 |
|
|
subject: authenticating website users with mysql dbase
|
|
|