在数据库中保存塞尔维亚语拉丁字符 [英] Saving serbian latin characters in database

查看:269
本文介绍了在数据库中保存塞尔维亚语拉丁字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在保存数据库中的塞尔维亚语拉丁字符时遇到问题,但只有当我从我的jsf应用程序保存。当我直接使用SQLyog在数据库中插入一些行时,一切都很好。当我尝试从应用程序中插入一些东西而不是字符:čć code>在数据库中插入问号。

I have problem with saving serbian latin characters in database, but only when I save it from my jsf application. When I inserting some rows in database directly using SQLyog, everything is fine. When I try insert something from application instead of characters: č, ć and đ in database are inserted question marks.

另一方面,当我从数据库中读取该行时,一切都显示正确,没有问号。

On the other hand, when I read that row from database everything is shown correctly, without question marks.

推荐答案


当我尝试从应用程序中插入一些东西,而不是字符:数据库中的č,ć和đ插入问号。 p>

When I try insert something from application instead of characters: č, ć and đ in database are inserted question marks.

换句话说,MySQL JDBC驱动程序不支持最初提交字符的字符编码。当将字符数据发送到DB(例如可以是ISO 8859-1)时,MySQL JDBC驱动程序默认为平台默认编码。您需要通过在JDBC URL中指定 useUnicode characterEncoding 参数来告诉它不要这样做。

In other words, the MySQL JDBC driver doesn't support the character encoding in which the characters are originally been submitted with. The MySQL JDBC driver defaults to the platform default encoding when sending character data to the DB, which may be for example ISO 8859-1. You need to tell it not to do that by specifying the useUnicode and characterEncoding parameters in the JDBC URL.

jdbc:mysql://localhost:3306/db_name?useUnicode=yes&characterEncoding=UTF-8

当你使用Facelets作为视图技术时,JSF在渲染HTML内容和处理提交时本身已经默认为UTF-8参数值。

When you're using Facelets as view technology, JSF defaults by itself already to UTF-8 when it comes to rendering HTML content and processing submitted parameter values. So the problem is at least not in there.

  • Unicode - How to get the characters right? - Databases
  • MySQL Connector/J Manual - 19.3.4.4. Using Character Sets and Unicode

这篇关于在数据库中保存塞尔维亚语拉丁字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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