SqlServer的The result set has no current row错误处理

错误描述

Integer totalCount = jdbcTemplate.query("select count(*) as count from xxx", (rs) -> {
      return rs.getInt("count");
    });

错误信息

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The result set has no current row.
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:228)
	at com.microsoft.sqlserver.jdbc.SQLServerResultSet.verifyResultSetHasCurrentRow(SQLServerResultSet.java:510)
	at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getterGetColumn(SQLServerResultSet.java:1883)
	at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:1919)
	at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getValue(SQLServerResultSet.java:1900)
	at com.microsoft.sqlserver.jdbc.SQLServerResultSet.getInt(SQLServerResultSet.java:2135)

原因

此时游标没有指向真正的数据行。

解决

Integer totalCount = jdbcTemplate.query("select count(*) as count from xxx", (rs) -> {
      rs.next();
      return rs.getInt("count");
    });

参考

com.microsoft.sqlserver.jdbc.SQLServerException: The result set has no current row

posted @ 2021-03-10 20:03  strongmore  阅读(694)  评论(0编辑  收藏  举报