结果集异常-在结果集开始之前我很难从ResultSet对象。这是我的代码: String sql = "SELECT type FROM node WHERE nid = ?";
PreparedStatement prep = conn.prepareStatement(sql);
int meetNID = Integer.parseInt(node.get(BoutField.field_meet_nid));
prep.setInt(1, meetNID);
ResultSet result = prep.executeQuery();
result.beforeFirst();
String foundType = result.getString(1);
if (! foundType.equals("meet")) {
throw new IllegalArgumentException(String.format("Node %d must be of type 'meet', but was %s", meetNID, foundType));
}错误跟踪:Exception in thread "main" java.sql.SQLException: Before start of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1072)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:986)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:981)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.ResultSetImpl.checkRowPos(ResultSetImpl.java:841)
at com.mysql.jdbc.ResultSetImpl.getStringInternal(ResultSetImpl.java:5656)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5576)
at nth.cumf3.nodeImport.Validator.validate(Validator.java:43)
at nth.cumf3.nodeImport.Main.main(Main.java:38)我在这里做错什么了?
3 回答
千万里不及你
TA贡献1784条经验 获得超9个赞
result.next(); String foundType = result.getString(1);
if(result.next()){ foundType = result.getString(1);}
森栏
TA贡献1810条经验 获得超5个赞
result.first();
幕布斯6054654
TA贡献1876条经验 获得超7个赞
ResultSet rs = stmt.executeQuery();while (rs.next()){ int foo = rs.getInt(1); ...}
添加回答
举报
0/150
提交
取消