How can I solve this error and what is the problem?
Here is my code:
String sql = "select min(pressure),max(pressure),avg(pressure) from userinfo";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
String add1 = rs.getString("min(pressure)");
min_pressure.setText(add1);
String add2 = rs.getString("max(pressure)");
max_pressure.setText(add2);
String add3 = rs.getString("avg(pressure)");
avg_pressure.setText(add3);
}
catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}
This results in the exception:
java. sql. SQLException: Before Start Of ResultSet
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)");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With