【问题标题】:How to store the text in other languages than English?如何以英语以外的其他语言存储文本?
【发布时间】:2015-09-26 11:16:35
【问题描述】:

在我的项目中,我想将泰米尔语字符存储在数据库中。所以我用数据类型 nvarchar(50) 为它创建了列。

Hibernate 将 nvarchar 转换为可序列化的。如何设置此列的值?

谁能帮忙解决这个问题?

【问题讨论】:

  • 我猜你必须通过扩展 SQLServerDialect 来编写自定义方言,该方言映射到 nchar、nvarchar 或 ntext 等数据类型。类似registerColumnType(Types.VARCHAR, 255, "nvarchar($l)")

标签: java sql sql-server hibernate


【解决方案1】:

我猜你必须通过扩展映射到数据类型的 SQLServerDialect 来编写自定义方言。

public class CustomSQLServerDialect extends SQLServerDialect {

public CustomSQLServerDialect() {
    super();

    // Use Unicode Characters
    registerColumnType(Types.VARCHAR, "nvarchar($l)");        
  }
}

【讨论】:

  • @Amough,谢谢,它部分解决了我的问题。它允许在 db 中添加泰米尔语字体,但是在检索它时会显示 ?????像这样
  • 您是否将hibernate.connection.CharSet,hibernate.connection.characterEncoding 属性设置为UTF8 并将hibernate.connection.useUnicode 设置为true。
  • @Madhesh,使用以上三个休眠属性尝试将数据库连接字符串设置为<property name="connection.url">jdbc:mysql://localhost/MyDB?useUnicode=true&characterEncoding=utf-8</property>
【解决方案2】:

Madhesh,对于在数据库中的任何字段中包含其他语言字符,您无需担心类型本身,但您需要检查您的字段或表甚至数据库本身使用的编码(整理)。

最常见的是utf8_general_ci:

Which is the best character encoding for Japanese language for DB, php, and html display?

我相信您可以通过用于访问和修改数据库的工具来更改这些排序规则。以下是有关字符编码和排序规则的更详细答案:

What does character set and collation mean exactly?

不过,泰米尔语似乎是一个特例,如果 UTF-8 编码还不够,有一个 open-tamil project for Tamil text processing in Github 可以帮助您进一步。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-30
    • 2015-04-30
    • 1970-01-01
    相关资源
    最近更新 更多