Resultset Exception - Before Start of Result Set

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);
}

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

Add a call to user.next(); before trying to read the first row. You are literally before the first row. Typically, you would use a loop like

while (user.next()) {
int id = user.getInt("id");
int counter = user.getInt("counter");
System.out.println("Id: " + id + " | Counter: " + counter);
}

The ResultSet.next() Javadoc says (in part),

A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.

java. sql. SQLException: Before Start Of Result Set. how Can I Solve IT?

The ResultSet javadoc says (in part) initially the cursor is positioned before the first row. Advance the resultset cursor to the first row by calling next() like

rs = pst.executeQuery();
rs.next(); // <-- or if (rs.next()) {
String add1 = rs.getString("min(pressure)");

java.sql.SQLException: Before start of result set

You access the data in a ResultSet object through a cursor. Initially cursor points to before first row.

while(rs.next()) {
String tittle=rs.getString("tittle");
....

}

More to it, your query might return more than one row, in that case, you may want to store the results in a collection, List<Map<String, String>>, where each entry in the list represents one row from your query resutls and the map hold the column name vs column value.

Getting an error before start of result set from mysql java

Why don't you use INNER JOIN in your query to make it simpler? I guess you don't need two separate sql statement and execute them separately. In stead you can use join query to merge the data from two tables employee and activeemployees and fetch data from there. It will be much faster, too.

You may try this new query in your resultset:

ResultSet myRs = myStmt.executeQuery("SELECT E.firstName AS firstName, E.lastName AS lastName FROM employee E INNER JOIN activeemployees A ON E.IDnumber = A.IDnumber");

And then, new ResultSet, myRs2 is not needed anymore. And you can use following code:

while (myRs.next()) {
pane.add(new Label(myRs.getString("firstName")+","+myRs.getString("lastName"),20,20));
}


Related Topics



Leave a reply



Submit