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)

原因

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

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

解决

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

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

上一篇:logstash6-mysql同步数据到es


下一篇:Centos7 安装Oracle JDK