mybatis查询count返回 <== Row: 0
来源:互联网 发布:邮件服务器域名设置 编辑:程序博客网 时间:2024/06/16 15:37
首先count的返回为0肯定不是统计结果为0,这里的情况是在服务器做查询,根据打印的sql到数据库去查询count是有统计量的,返回的row是1,就是有统计结果的。但是服务器上打印的sql就显示 <== Row: 0,这个是因为服务器发送查询sql到数据库去执行过程中有中文,这个中文在你代码层面可能是转码过的,所以在代码层面不会显示乱码,这才是迷惑人的地方,而且如果数据库表的字符集也是utf-8,那如果这个问题说是中文编码问题引起就更让人费解了,将sql直接拷贝到数据库去执行没问题,但是通过代码连数据库去执行sql就返回0行结果集(不是统计结果为0),笔者通过查询资料,做了个修改,解决了这个问题,因为数据库是通过jndi配置,jndi又在tomcat的server.xml集成,所以在jndi那段连数据库url中加入了字符转码的配置,默认是连数据库的url中不需要配置的。没错,一个完整请求过来笔者先在代码层进行了utf-8转码了,现在还在连数据库的层面再转utf-8,这里比较合理的解释就是莫名其妙的环境问题了。具体配置如下:
39 <!--配置MySQL数据库的JNDI数据源-->40 <Resource 41 name="jdbc/mysql"42 auth="Container" 43 type="javax.sql.DataSource"44 maxActive="100" 45 maxIdle="30" 46 maxWait="10000"47 username="root" 48 password="root"49 driverClassName="com.mysql.jdbc.Driver"50 url="jdbc:mysql://192.168.1.144:3306/leadtest?useUnicode=true&characterEncoding=utf-8"/>51 52 <!--配置SQLServer数据库的JNDI数据源-->上面的&是转义后的&的意思,这里?后如果要多个参数则&符号都需要转义。
阅读全文
0 0
- mybatis查询count返回 <== Row: 0
- Message = "SQL insert, update or delete failed (expected affected row count: 1, actual affected row count: 0). Possible causes:
- Mybatis查询返回多个sum、count数据解决方案
- mybatis 查询 resultMap="" 只返回一条数据
- 使用mybatis,在添加数据的时候返回主键,当查询count和属性字段怎么接收返回数据
- mybatis返回count(*)的整数值
- Unexpected row count: 0 expected: 1
- 一对多 group by 后 查询 count(*) ,但是 count(*)=0的不能显示
- mybatis查询select count()类型转换
- mysql查询记录,无记录 count(*)返回0,max()返回null
- HQL count(*) 查询返回的类形
- Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1解决方案
- Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
- Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
- 错误Batch update returned unexpected row count from update [0]; actual row count: 0;
- Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
- Batch update returned unexpected row count from update :0 actural row count 0, excepted :1
- Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
- js获取url的多个参数
- 74hc595
- Java设计模式-装饰者模式
- 多线程、方便扩展的Windows服务程序
- linux基础(二十一)管理系统存储
- mybatis查询count返回 <== Row: 0
- 基础
- Python之正则表达式
- TensorFlow全新的数据读取方式:Dataset API入门教程
- Redsi应用场景的介绍与分析
- Java正则表达式判断是否为手机号码
- 开源许可证教程
- 判断手机号
- shell之echo用法和有色输出