ResultSet returning nothing

I've been having this issue and I can't figure it out. I've got a application where a user enters in an e-mail address and password and clicks "login." It then connects to my SQL database to see if that e-mail and password combination exist together. If it does it's supposed to prompt me with a JOptionPane telling me that the user exists and get the 'id' in that row. Here is my code:

try
{
// Load the JDBC driver
ResultSet rs = null;
String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver
Class.forName (driverName);

// Create a connection to the database
serverName = "fedex.plastikracing.net";
mydatabase = "web5_db1";
url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
dbuser = "web5_u1";
dbpass = "password";
connection = DriverManager.getConnection (url, dbuser, dbpass);


Statement stmt = connection.createStatement ();
String sql = "SELECT id FROM users WHERE email = ? AND password = ?";
PreparedStatement pstmt = connection.prepareStatement (sql);
String password = new String (t_pass.getPassword ());
// Set the values
pstmt.setString (1, t_email.getText ());
pstmt.setString (2, passHash (password));
JOptionPane.showMessageDialog (login.this,"E-mail: " + t_email.getText () + "\nPassword: " + passHash (password) , "Connection Error",
JOptionPane.ERROR_MESSAGE);
rs = pstmt.executeQuery ();
rs.next ();
int id = rs.getInt (1);
JOptionPane.showMessageDialog (login.this,id , "UserID",
JOptionPane.ERROR_MESSAGE);
}
catch (SQLException e)
{
// Could not connect to the database
JOptionPane.showMessageDialog (login.this,"Error: " + e.getMessage (), "Connection Error",
JOptionPane.ERROR_MESSAGE);
}
catch (ClassNotFoundException e)
{
// Could not find the database driver
JOptionPane.showMessageDialog (login.this,"Could not find the database driver. \n" + e.getMessage (), "Connection Error",
JOptionPane.ERROR_MESSAGE);
}

I also have a JOptionPane in there for testing purposes that pops up whenever they click "login" that displays the exact values being inserted into my SQL query. My problem is, when I run this I get:

"Illegal operation on empty result set"

If I type in the query in phpMyAdmin, it runs just fine.
[2917 byte] By [tristanlee85] at [2007-11-20 8:15:20]
# 1 Re: ResultSet returning nothing
Are you sure the passhash(..) method is doing what you expect?

Incidentally, you don't need to create a new String for the password, you can either just assign the password value to the password String, or just use the t_pass value directly:// instead of
String password = new String (t_pass.getPassword ());

// you can do this:
String password = t_pass.getPassword ();

// or even this:
pstmt.setString (2, passHash (t_pass.getPassword ()));That last one might be a step too far - readability is important.

Strings are immutable (read-only), so once set, the value cannot change (although you can give a String variable a new value).

Don't ask what it means, but rather how it is used...
L. Wittgenstein
dlorde at 2007-11-10 2:15:22 >
# 2 Re: ResultSet returning nothing
I figured it out. When creating the account and hashing the password, I wasn't assigning a value to password so it was hasing a string of nothing. The login and SQL part was working right.
tristanlee85 at 2007-11-10 2:16:25 >