标签:
boolean next()
throws
ResultSet cursor is initially positioned before
the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so
on.
When a call to the next method returns false,
the cursor is positioned after the last row. Any invocation of a ResultSet method which requires a current row will result in a SQLException being
thrown. If the result set type is TYPE_FORWARD_ONLY, it is vendor specified whether their JDBC driver implementation will return false or
throw an SQLException on a subsequent call to next.
If an input stream is open for the current row, a call to the method next will
implicitly close it. A ResultSet object‘s warning chain is cleared when a new row is read.
true if the new current row is valid; false if
there are no more rowsSQLException -
if a database access error occurs or this method is called on a closed result setResultSet 的请求当前行的方法调用都会导致SQLException 被抛出。但如果查询的结果设置为TYPE_FORWARD_ONLY,next方法在这时候根据实现厂商的不同,可能会返回false也坑能会抛出SQLException 异常Statement statement = conn.createStatement();
ResultSet res = statement.executeQuery(selectSql);
if (!res.next()) {
//res is null
} else {
// res is not null
}ResultSet res = ...使用某种方法获取查询结果
int nRow = 0;
while(res.next()) {
++nRow;
}
res.beforeFirst();
// 其他代码不变ResultSet res = ...使用某种方法获取查询结果 res.last(); final int nRow = res.getRow(); res.beforeFirst(); // 其他代码不变
MySQL的JDBC判断查询结果是否为空以及获取查询结果行数的方法
标签:
原文地址:http://blog.csdn.net/sky453589103/article/details/51354668