Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

authenticating website users with mysql dbase

 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your query is this:

Do you have any users with the username "username" and the password "password?
 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahhh...I see now..My mistake. thanks
[ May 03, 2007: Message edited by: Tontang Bei ]
 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2596
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2596
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(...).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic