Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Check whether a value exists ina database or not

 
Sam Alex
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

tell me the easiest way to find whether a data exists in a database or not.The database is created in PostgreSQl.the code is written in servlet.Ac6tually my database table contains 5 columns.They are name company,designation,userid and password.I have to check whether user id and passsword exists in this database or not.Send me a reply as soon as possible.

regarsds
Sam
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam,
Welcome to JavaRanch!

select count(*) from table where userId = ? and password = ?
rs.next();
if ( rs.getInt(0) == 0 ) {
// doesn't exist
} else {
// exists
}

For the future, we have a JDBC forum for questions like this.
 
Marilyn de Queiroz
Sheriff
Posts: 9068
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
moving to the JDBC forum
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic