java.sql.SQLException: Before start of result set"

I'm having a problem with getting some data from a database. The problem is that I am getting an exception, "java.sql.SQLException: Before start of result set".

I think the it might be coded right. Perhaps it's a problem with MySQL. Can any one give me some help here? Thanks in advance....

I've trimmed down the code to just the method.

rs, st and conn are declared global variables in the class.

/* This method queries the database and sets the

variables that we'll "get" from the jsp form.*/

publicint setInputElementValues(String query)

{

try{

Class.forName("com.mysql.jdbc.Driver").newInstance();

conn = DriverManager.getConnection("jdbc:mysql://francis:3306/addressbook?autoReconnect=true",

"root",

"password"

);

Calendar rightNow = Calendar.getInstance();

//System.out.println("Got a DB Connection" + rightNow.toString());

st = conn.createStatement();

//System.out.println("Getting ready to execute this query: " + query);

rs = st.executeQuery(query);

rs.beforeFirst();//set result set to first line

/*set the field values*/

firstName = rs.getString("FirstName");

/*

lastName = rs.getString("LastName");

addressLn1 = rs.getString("AddressLn1");

addressLn2 = rs.getString("AddressLn2");

city= rs.getString("City");

state = rs.getString("State");

zip = rs.getString("Zip");

country=rs.getString("Country");

*/

}

catch (Exception ex)

{

ex.printStackTrace();

}

finally

{

try{

if (rs !=null){ rs.close();}

if (st !=null){ st.close();}

if (conn !=null){ conn.close();}

}

catch (Exception ex)

{

ex.printStackTrace();

System.out.println("could not close rs, st or conn");

}

}

return 1;

}

[3198 byte] By [mikelupoa] at [2007-11-26 15:40:20]
# 1
RTFAPI. Go read up on ResultSet.beforeFirst().
es5f2000a at 2007-7-8 21:58:47 > top of Java-index,Java Essentials,Java Programming...