PreparedStatement 在mysql下中文乱码解决方案
来源:互联网 发布:淘宝双11实时销售额 编辑:程序博客网 时间:2024/05/14 21:31
在顶目中无意中碰到PreparedStatement 在存DB时出现乱码,困扰了好久终于解决问题
问题代码如下
pstmt = con.prepareStatement(INSERT_OFFLINE); pstmt.setString(1, username); pstmt.setLong(2, messageID); pstmt.setString(3, StringUtils.dateToMillis(new java.util.Date())); pstmt.setInt(4, msgXML.length()); pstmt.setString(5, “中文内容”); pstmt.executeUpdate();
调试时可以看到在 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
问题解决
- PreparedStatement 在mysql下中文乱码解决方案
- PreparedStatement 在mysql下中文乱码解决方案
- PreparedStatement 在mysql下中文乱码解决方案
- PreparedStatement 在mysql下中文乱码解决方案
- PreparedStatement 在mysql下中文乱码解决方案
- Prepared Statement在mysql下中文乱码解决方案
- Prepared Statement在mysql下中文乱码解决方案
- jsp+mysql 在 preparedStatement中 中文乱码解决
- jsp+mysql 在 preparedStatement中 中文乱码解决
- Linux下mysql中文乱码解决方案
- Linux下mysql中文乱码解决方案
- Linux下mysql中文乱码解决方案
- Mac 下Mysql数据库中文乱码解决方案
- Linux下mysql中文乱码解决方案
- Mac下Mysql中文乱码解决方案
- PreparedStatement在MySQL下中文显示为??的问题
- emacs 在shell下中文乱码解决方案
- PreparedStatement下中文乱码的问题
- Java中的Enum的使用与分析
- XPath语法
- 设计的核心任务之二:信息隐藏
- NYOJ 489 哭泣天使(网络流)
- 野人传教士问题
- PreparedStatement 在mysql下中文乱码解决方案
- misc it 3D打印机离我们有多远
- 编码的意思
- USB枚举过程分析
- 别了,教研室!
- Spring框架第一讲
- List存储Java对象
- transient————>serializable
- 用动态规划找到两个字符串的最长公共子序列