jdbc连接数据库,查询条件为汉字,查询无结果解决办法
2015-06-04 17:16
471 查看
问题描述:
select * from student where name='张三'
在数据库中输入该查询语句时,有结果集。
用jdbc连接数据库,在Java程序中执行时查询不到结果集。
解决方法:
该问题为编码问题,需要进行参数转码,在连接中添加:useUnicode=true&characterEncoding=GBK
例如:
connection = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=root&useUnicode=true&characterEncoding=GBK"
);
select * from student where name='张三'
在数据库中输入该查询语句时,有结果集。
用jdbc连接数据库,在Java程序中执行时查询不到结果集。
解决方法:
该问题为编码问题,需要进行参数转码,在连接中添加:useUnicode=true&characterEncoding=GBK
例如:
connection = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=root&useUnicode=true&characterEncoding=GBK"
);
相关文章推荐
- sql基础笔记备忘
- Mysql用户与权限管理
- 查找数据库的物理位置
- sql去重复
- Redis学习笔记1--入门篇
- ubantu下安装mysql教程以及碰到的问题总结
- sql ntext数据类型怎么查询
- linux安装mongodb
- vs2013 ODBC连接Oracle 学习记录2
- mysql数据库编码设置
- sqlserver 常用存储过程集锦
- Centos编译安装 LAMP (apache-2.4.7 + mysql-5.5.35 + php 5.5.8)+ Redis
- MySQL事物系列:1:事物简介
- SQL Server用户登录失败
- oracle 11g sql developer安装后无法使用
- Linux下为PHP添加MongoDB扩展
- Haproxy+Keepalived+MySQL实现读均衡负载
- 构建高性能web之路------mysql读写分离实战
- Oracle传输表空间学习
- mysql用户资源限制