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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Help me on userlogin  RSS feed

 
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 ?
 
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.
 
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.
 
author & internet detective
Sheriff
Posts: 38569
656
Eclipse IDE Java VI Editor
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!