爲什麼我會得到我的查詢SQLException
?的SQLException:無效的遊標狀態
PreparedStatement stmt = con.prepareStatement("SELECT note FROM NOTES4EME WHERE id=?");
stmt.setString(1,"1");
ResultSet a = stmt.executeQuery();
return a.getInt(1);
我錯過了什麼?
我有一個方法:
public int afficheNote(int id) throws ClassNotFoundException, SQLException {
Class.forName("org.apache.derby.jdbc.ClientDriver");
String url = "jdbc:derby://localhost:1527/TLdb;create=true;user=root;password=root";
Connection con = DriverManager.getConnection(url);
String query = "SELECT NOTES FROM NOTES4EME WHERE ID = '" + id + "'";
//PreparedStatement stmt = con.prepareStatement(query);
PreparedStatement stmt = con.prepareStatement("SELECT note FROM NOTES4EME WHERE id=?");
stmt.setString(1,"1");
ResultSet a = stmt.executeQuery();
if (a.next()) {
return a.getInt(1);
}
return -1;
}
和我打電話的.JSP這種方法:調用getInt
ResultSet a = stmt.executeQuery();
if (a.next()) {
return a.getInt(1);
} else {
throw new IllegalArgumentException("Nothing found for 1...");
}
異常的全堆棧跟蹤? –