`String query = "select count(book_id) as book_id from library_books_details where book_id = ?";`
PreparedStatement psEnd = collegeCon.prepareStatement(query);
psEnd.setInt(1, bookId);
答案 0 :(得分:1)
ResultSet rs = psEnd.executeQuery();
if (rs.next()) {
int count= rs.getInt(1);
System.out.println("Count= " + count);
} else {
System.out.println("error: could not get the record counts");
}
答案 1 :(得分:1)
根据http://docs.oracle.com/javase/tutorial/jdbc/basics/processingsqlstatements.html
数据库访问流程
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String strColumn = rs.getString("....");
int intColumn= rs.getInt("....");
}