Home  >  Article  >  Database  >  PreparedStatement 在MySQL下中文乱码解决方案

PreparedStatement 在MySQL下中文乱码解决方案

WBOY
WBOYOriginal
2016-06-07 17:13:201074browse

PreparedStatement 在MySQL下中文乱码解决方案

在顶目中无意中碰到PreparedStatement  在存DB时出现乱码,,困扰了好久终于解决问题

问题代码如下

调试时可以看到在   pstmt.executeUpdate();  行 pstmt  中的 “中文内容” 变成  ????

原因是设置datasource 的driver 时jdbc.url=jdbc:mysql://192.168.12.22:3306/ts 没有指定编码

可以按如下修改

jdbc.url=jdbc:mysql://192.168.12.22:3306/ts?characterEncoding=utf8

问题解决

 

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn