Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database Connection please help

 
nash avin
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a servlet that basically connects to the database if the userid and password is correct.
I have a "login.html" page where the user enters the "userid" and "password".The servlet does the checking and grants access to the user.
My question is as follows.As soon as I startup tomcat type in the url login.html,then press the submit button,(both the fields are blank) the servlet says "ok" this is this information is present in the database.It should say "not ok".Hope I question is clear.The code for the servlet is given below.


Regarding the database.The fields in the database are "username" and "password" and it has one tuple
"xyz" and "xyz"

Hope that my question is rightly put.
Thanking you
AS
 
Billybob Marshall
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2 problems:
1) move those 'private' variables into your method. Otherwise, 2 near-concurrent hits to the servlet will walk on each other's values, leading to serious bugs.
2) in the method, initialize username and password to null, not to "" - then it will be closer to what you want.
 
nash avin
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the prompt reply.It did work the way you said it.Will keep posting for errors/doubts.
AS
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic