我正在研究jdbc的教程,但没有显示它抛出异常的行数。我一直试图找到解决方案但无济于事。任何人都可以对这个问题有所了解。
Connection conn = null;
Statement stmt = null;
ResultSet rs= null;
try {
conn = DriverManager.getConnection(CONN_STRING, USERNAME, PASSWORD);
stmt =conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery("SELECT * FROM states");
rs.last();
System.out.println("Number of rows: " +rs.getRow());
} catch (SQLException e) {
System.err.println(e);
} finally {
if (conn != null) {
conn.close();
}
}
}
}
答案 0 :(得分:0)
此处异常与获取结果集的大小无关。
查看documentation的SQLInvalidAuthorizationSpecException:
This indicates that the authorization credentials presented during connection establishment are not valid.
其次,要获取结果集中的行数,可以使用rs.getFetchSize()
而不是逻辑。