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"
更改之后就好了;记录一下,这个错误浪费了半天的时间
--------------------------------------------------------------------------------------------------------------------------------------------------------
目前的博客发表主要以记录笔记为主,可能部分内容有些浅显,望各路大牛勿喷,请您雅正