Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 17:13:20
Original
1076 people have browsed it

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!