Java 无法在变量中存储结果集的结果

Java 无法在变量中存储结果集的结果,java,mysql,jdbc,Java,Mysql,Jdbc,我在将b_id存储在变量bId中时遇到了问题,因此我可以进一步使用它。 请帮忙。 它显示“结果集开始前”错误 Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/librarian_db","root","tiger"); PreparedStatement ps2 = con.prepareStatem

我在将b_id存储在变量bId中时遇到了问题,因此我可以进一步使用它。 请帮忙。 它显示“结果集开始前”错误

   Class.forName("com.mysql.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/librarian_db","root","tiger");
    PreparedStatement ps2 = con.prepareStatement("select b_id from books  where Call_num= ?");
    ResultSet rs;
    ps2.setString(1, callNo);
    rs=ps2.executeQuery();
    bId = rs.getString(1);
    System.out.println(bId);
您需要使用rs.next,例如:

if(rs.next()){
    bId = rs.getString(1);
    System.out.println(bId);
}
如果需要多个结果,可以在以下情况下使用:

while(rs.next()){
    bId = rs.getString(1);
    System.out.println(bId);
}

那是什么麻烦?错误是什么?java.sql.SQLException:在结果集开始之前,这是错误