ResultSet exception - before start of result set
Basically you are positioning the cursor before the first row and then requesting data. You need to move the cursor to the first row.
result.next();
String foundType = result.getString(1);
It is common to do this in an if statement or loop.
if(result.next()){
foundType = result.getString(1);
}
Every answer uses .next()
or uses .beforeFirst()
and then .next()
. But why not this:
result.first();
So You just set the pointer to the first record and go from there. It's available since java 1.2 and I just wanted to mention this for anyone whose ResultSet
exists of one specific record.
You have to do a result.next() before you can access the result. It's a very common idiom to do
ResultSet rs = stmt.executeQuery();
while (rs.next())
{
int foo = rs.getInt(1);
...
}