• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

authenticating website users with mysql dbase

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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(...).
 
reply
    Bookmark Topic Watch Topic
  • New Topic