This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Result set" Watch "Result set" New topic
Author

Result set

Amritpal Singh Moomie
Ranch Hand

Joined: Sep 24, 2010
Posts: 32
Hi i am building a basic login application with jdbc
But i am new to java ,
error with my code is that it will let me login only if enter the last record of the database ( Most recently added)

Can anybody help me what change should i make



}
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19693
    
  10

You should change your code so it doesn't read every record in the database. As it is you do your comparisons on every record, but you only use the result after reading all the records. So you only use the result of the comparisons on the last record.

In fact you should only read records which match the user ID and password. If there are any such records then you can login. If there aren't any, then you can't login.
Amritpal Singh Moomie
Ranch Hand

Joined: Sep 24, 2010
Posts: 32
How can i do comparison on every record and get result?

Do you have any code example or tutorial.


thanks
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19693
    
  10

You would simply use a WHERE clause in your SQL statement. That should be covered very near the beginning of whatever you are using to learn SQL.

And when you do that, make sure to use a PreparedStatement to implement it. That's covered in the standard JDBC tutorial.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 43381
    
  32
Moving to our databases forum.
 
Don't get me started about those stupid light bulbs.
 
subject: Result set
 
It's not a secret anymore!