Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Check whether a value exists ina database or not

 
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
 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • 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.
 
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
moving to the JDBC forum
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic