This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
    Bookmark Topic Watch Topic
  • New Topic

Help me on userlogin

 
Shounak Kundu
Ranch Hand
Posts: 60
IBM DB2 Eclipse IDE Fedora
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi, I am writing this code.



My problem is that the boolean variable userexists is always returning true. How can I fix it? Can anybody help me ?
 
Ngoc Sinh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Report post to moderator
There are three things you should be carefull:

1. SQL query doesn't check if the password is match case or not.
2. You should you prepareStatement and set parameter instead of plus variable into your query string, it may cause some sql error.
3. Statement.execute() always return true if the queryString return a ResultSet, although that the ResultSet have no record.

I recommend you do this way:
1. Select user have the same username with the input.
2. If user existed, check the password is equal or not. Else response invalid username or something.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Report post to moderator
Ngoc Sinh wrote:1. SQL query doesn't check if the password is match case or not.

It checks for equality, which is case-sensitive.

I recommend you do this way:
1. Select user have the same username with the input.
2. If user existed, check the password is equal or not. Else response invalid username or something.

There's no reason not to combine the two operations in the SQL query as is being done.

But ultimately, you need to see if there were any results: Statement.execute(...) doesn't do this; it's generally for statements that don't return a result set. (You can *get* the result set, but why take the extra step?) Try using executeQuery(...) and seeing if the result set has any entries: rs.next() returns a boolean.

Check out the java.sql.Statement API docs for further info--they're worth knowing.
 
Shounak Kundu
Ranch Hand
Posts: 60
IBM DB2 Eclipse IDE Fedora
  • Mark post as helpful
  • send pies
  • Report post to moderator
You guys are awesome, thanks a lot mate.....

But, now I have different problem , and I have posted it here. I am now getting ResultSet.next() was not called Exception
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Report post to moderator
Can't help if we can't see what you're trying.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34187
340
Eclipse IDE Java VI Editor
 
    Bookmark Topic Watch Topic
  • New Topic