zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Django 框架
    Git 教程
    Vue详解
    pycharm激活码
    通过元类创建一个Python类
    re模块
    selenium模块
    Beautifulsoup模块基础详解
    requests库
    Urllib库
  • 原文地址:https://www.cnblogs.com/strongmore/p/14513908.html
Copyright © 2011-2022 走看看