Hello,
I had some problems which trouble me. I solved them but I can't believe that the behavior I found is normal.
I use Java 1.6 and mysql 5.5 (from EasyPHP 5.3.7) running the system windows XP pro sp3.
first: Using the following code, having a jdbc - connection object open named con:
public int test (String test){
int id1 = -1;
String sql ="";
Statement s = null;
ResultSet rs =null;
try {
sql = "Select * from Country WHERE Country like '"+test + "'";
s = con.createStatement();
rs = s.executeQuery(sql);
while (rs.next()) { id1 = rs.getInt("id"); }
rs.close(); s.close();
} catch (SQLException ex) {System.out.println(ex+"a"); }
return id1;
}
I get one row as a result as it should be, but if I don't use while (rs.next() ) it doesn't work. I get an error because id stays on row -1 !!! The error appears if I step over rs.getInt("Id"). It does not appear with while (rs.next() ) { } but it appears without:
java.sql.SQLException: Before start of result set ID Deutschland = -1
I don't understand this. It happens with the innoDB and also with MyIsam.
Thanks for help
Thommy
Edited 7 time(s). Last edit at 01/15/2012 01:16PM by Thomas Willms.