Spring 3 MVC + MySQL:不能存储€字符 [英] Spring 3 MVC + MySQL: cannot store € character

查看:161
本文介绍了Spring 3 MVC + MySQL:不能存储€字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Hibernate和MySQL 5创建了Spring 3 MVC。在Web表单中,我在字段中输入单个字符(即只有一个字符)。当我尝试保存数据时,出现以下异常:

  java.sql.BatchUpdateException:数据截断:Data truncated对于第1行的'name'列

'name'是我模型对象上的一个字符串。 'name'列是MySQL中的数据类型VARCHAR(80)。我也尝试在TEXT列中输入€,结果相同。



我为我的webapp配置了一个CharacterEncodingFilter,而我的数据库连接字符串如下所示:

  JDBC:MySQL的://本地主机/ baseApp zeroDateTimeBehavior = convertToNull&放大器;放大器;了useUnicode =真放大器;放大器;的characterEncoding = UTF8 

任何想法可能是什么问题?

更新:

我不认为MySQL与这个问题有任何关系。我已经拦截了HTTP POST,然后我的模型对象的属性被设置并且€被正确编码为%80。然而,当我询问我的模型对象的属性时,它们就是?的。



有什么想法? 你确定MySQL数据库存在suports UTF-8?我认为默认安装设置使用latin1。您还需要确保my.ini配置文件中[mysql]和[mysqld]的'default-character-set'设置为'utf8'。此外请确保表格是使用UTF-8设置构建的。


I have Spring 3 MVC set up with Hibernate and MySQL 5. In a web form, I enter a single character into a field, € (i.e. just the one character). When I then attempt to save the data, I get the following exception:

java.sql.BatchUpdateException: Data truncation: Data truncated for column 'name' at row 1

'name' is a String on my model object. The 'name' column is of datatype VARCHAR(80) in MySQL. I have also tried entering a € into a TEXT column, with the same result.

I have configured a CharacterEncodingFilter for my webapp and my DB connection string looks like this:

jdbc:mysql://localhost/baseApp?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf8

Any ideas what the problem might be?

Update:

I don't think MySQL has anything to do with this issue. I have intercepted the HTTP POST before the properties of my model object are set and the € is properly encoded as %80. When I interrogate the properties of my model object, however, €'s are simply ?'s.

Any thoughts?

解决方案

Are you sure the MySQL database suports UTF-8? I think the default install settings uses latin1. You also need to make sure that the 'default-character-set' for [mysql] and [mysqld] in the my.ini configuration file is set to 'utf8'. Furthermore make sure the table was built with UTF-8 settings.

这篇关于Spring 3 MVC + MySQL:不能存储€字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆