• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sql error when connecting to mysql error

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm pretty new to this so maybe be stupid question but here goes:

I have created a servlet that via an sql statement get login and password value from mysql database. I then compare this to user and param parameters entered in html login page.

I then compare the userparam and userpassord against the database information and I get the following error:
Error! Opening connection has failed: java.sql.SQLException: Before start of result set
java.sql.SQLException: Before start of result set

I cannot see what is causing this error.
I'm really struggling here, here the code causing error:
String queryEmpUser = "SELECT * FROM employees WHERE ((login = '" + userParam +"')"
+" AND (password = '"+ passwordParam +"'))";
String queryClients = "SELECT * FROM clients";

//Store username information
stmtEmpUser = connection.createStatement();
stmtClients = connection.createStatement();
rsEmpUser = stmtEmpUser.executeQuery(queryEmpUser);
ResultSetMetaData rsmdEmp = rsEmpUser.getMetaData();

Vector Clients = new Vector();
System.out.println("Query = " +queryEmpUser + "<P>");
System.out.println("userParam = " +userParam + "<P>");

//This is where error is occuring - if ( rsEmpUser.getString("login").equals(userParam) &&
rsEmpUser.getString("password").equals(passwordParam) ) {

Can someone help please?

Cheers Joe
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ResultSets start in a 'before first' position, you always have to call rs.next() before trying to access the data in the ResultSet. You should always check the result of rs.next() to make sure there is actually some thing to read.

In your case, you can edo something like this:
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is almost completely a JDBC question, so I'll move it to that forum.

Cheers, Dave.

[ March 26, 2006: Message edited by: David O'Meara ]
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Your code should be something like
while (rs.next()) {
///Your logic

}
[ March 27, 2006: Message edited by: vishwanath nadimpally ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic