• mybatis日志能正常打印出正确sql执行语句;数据库有内容;却查询不出来


    首先是返回值封装为List的时候获取不到值;为单个对象的时候正常

    这个是要执行的调试语句;发现执行完毕控制台如下;sql正确;对象和数据库关系映射也正确;

    //执行语句
            List<Object> list = sqlSession.selectList("test.getUserByName", "");
            for (Object user : list) {
                System.out.println("user"+user);
            }
    执行完毕出现下面的问题
    DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.
    DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
    DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
    DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
    DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
    DEBUG [main] - Opening JDBC Connection
    DEBUG [main] - Created connection 733957003.
    DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@2bbf4b8b]
    DEBUG [main] - ooo Using Connection [com.mysql.jdbc.JDBC4Connection@2bbf4b8b]
    DEBUG [main] - ==> Preparing: select * from user where username LIKE '%五%' 
    DEBUG [main] - ==> Parameters: 
    DEBUG [main] - <== Total: 0
    DEBUG [main] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@2bbf4b8b]
    DEBUG [main] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@2bbf4b8b]
    DEBUG [main] - Returned connection 733957003 to pool.
    
     

    然后写了个最简单的demo发现仍然出现问题;检查到最后发现是数据源的url编码问题;没有设置为Utf-8;具体原理还没有找到;希望各位可以解读下原理

    jdbc:mysql://localhost:3306/demo?characterEncoding=utf-8" 

    更改之后就好了;记录一下,这个错误浪费了半天的时间

  • 相关阅读:
    .NET 动态脚本语言
    webParts与Web部件
    比较JqGrid与XtraGrid
    XtraGrid滚轮翻页
    Python------继承
    Python 私有化类的属性
    Python print 输出不换行,只有空格
    Python--函数参数类型
    手推FP-growth (频繁模式增长)算法------挖掘频繁项集
    Python 返回多个值+Lambda的使用
  • 原文地址:https://www.cnblogs.com/404code/p/10617669.html
Copyright © 2020-2023  润新知