int bookID
返回值 0
,它应该返回 1
。 (表中的第一个 ID。)请帮忙。
public void ID(){
conn = ConnectDB();
String sql = "Select Book_ID From Student Biblio";
try {
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
if(rs.next()){
int bookID = rs.getInt(1); //IDTable
}
} catch (SQLException ex) {
Logger.getLogger(Student.class.getName()).log(Level.SEVERE, null, ex);
}
}
最佳答案
试试这个可能会对你有帮助
public void ID(){
conn = ConnectDB();
String sql = "Select Book_ID From Student Biblio";
try {
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
while(rs.next()){
int bookID = rs.getInt("Book_ID"); //IDTable
}
} catch (SQLException ex) {
Logger.getLogger(Student.class.getName()).log(Level.SEVERE, null, ex);
}
}
关于java - 如何获取 ResultSet 的整数值并将其分配给 int 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27277515/