Mybatis3使用JdbcOdbc驱动检索MS Access报No data found exception的解决方法

来源:互联网 发布:抽奖算法提高概率 编辑:程序博客网 时间:2024/06/07 09:22

原因:


This typically occurs when you try to read the value of a column multiple times. For example, this may throw "No data found":

ResultSet rs = statement.executeQuery(sql);while (rs.next()) {    if ("value1".equals(rs.getString("mycolumn")) || "value2".equals(rs.getString("mycolumn"))

只有jdbc-odbc桥接会有只能取一次值的这个问题,其他Jdbc驱动无。


而Mybatis3的ResultSetLogger:


  private void printColumnValues(int columnCount) throws SQLException {
    StringBuilder row = new StringBuilder();
    row.append("<==        Row: ");
    for (int i = 1; i <= columnCount; i++) {
      String colname;
      try {
        colname = rs.getString(i);

..........


也就是在正式从rs.getString取值前,ResultSetLogger已经调用过一次,所以会报No data found Java exception


解决方法:


log4j.properties 添加一行 log4j.logger.java.sql.ResultSet=ERROR

让ResultSetLogger在出错情况外不执行即可。



0 0