This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes authenticating website users with mysql dbase Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "authenticating website users with mysql dbase" Watch "authenticating website users with mysql dbase" New topic
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: 2497
    
    8

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 and ITIL foundation
youtube channel
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: 2497
    
    8

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