为什么我的查询会收到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中调用此方法:
<%
int a = mybean.afficheNote(1);
%>
答案 0 :(得分:0)
在调用typedef typename decltype(f(std::declval<T>()))::value_type R;
next
getInt
答案 1 :(得分:0)
ResultSet
Javadoc说(部分)最初光标位于第一行之前。所以你需要调用next
。添加类似
if (a.next()) {
return a.getInt(1);
}
return -1;