Oracle DB、Glassfish、Hibernate 和字符编码

发布于 2025-01-02 05:30:44 字数 892 浏览 2 评论 0原文

我们有一个使用 UTF-8 (NLS_CHARACTERSET = AL32UTF8) 的 Oracle 数据库。 然后我们在 Glassfish 中有一个使用 Hibernate 的 J2EE 应用程序。

使用 SQL Plus 或 SQL Developer 时,我们可以正确读取和写入数据,但无法以编程方式获取特殊字符。

阅读 ä 我们得到 √§

查看我尝试过的类似问题:

  • 调整 Hibernate 属性

    <属性名称=“hibernate.connection.characterEncoding”值=“utf8”/>
    

  • 在 Glassfish 中添加 defaultNChar=true 连接属性

  • 添加 defaultNChar code> 通过 Hibernate 连接属性

    <属性名称=“hibernate.connection.defaultNChar”值=“true”/>
    
  • 将字符集设置为utf8

    <属性名称=“hibernate.connection.charSet”值=“utf8”/>
    

但我仍然无法获取任何非基本 ASCII 的字符。

有什么提示我做错了什么吗?

编辑:对于 get 我的意思是使用 select 语句获取。使用调试器进行检查或与正确的(例如,"ä")字符串与断言进行比较。

We have an Oracle DB using UTF-8 (NLS_CHARACTERSET = AL32UTF8).
We then have a J2EE application in Glassfish which uses Hibernate.

While using SQL Plus or SQL Developer we can read and write the data correctly but we are not able to get special characters programmatically.

Reading an ä we get √§

Looking at similar questions I tried:

  • tuning Hibernate properties

    <property name="hibernate.connection.characterEncoding" value="utf8" />
    

  • adding the defaultNChar=true connection property in Glassfish

  • adding the defaultNChar connection property through Hibernate

    <property name="hibernate.connection.defaultNChar" value = "true"/>
    
  • setting the charset to utf8

    <property name="hibernate.connection.charSet" value="utf8" />
    

But I'm still not able to get any character which is not basic ASCII.

Any hint on what am I doing wrong?

Edit: with get I mean fetch with a select statement. Checking with a debugger or comparing with the correct (e.g., "ä") string with an assertion.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我们只是彼此的过ke 2025-01-09 05:30:44

正如使用 NVARCAR 对原始问题的评论中所讨论的,添加到 Hibernate 配置文件中的以下行似乎有效。

<property name="hibernate.connection.defaultNChar">true</property>

它对我有用。

As discussed in the comments to the original question using NVARCAR and the following line added to the Hibernate configuration file seems to work.

<property name="hibernate.connection.defaultNChar">true</property>

It did for me.

匿名。 2025-01-09 05:30:44

您还没有在数据源声明中提及任何有关连接 url 的内容。您是否尝试在连接 URL 上设置编码?

jdbc:mysql://localhost:3306/yourDB?useUnicode=true&characterEncoding=UTF-8

我无法测试oracle,但对于mysql它解决了问题。

You haven't said anything about your connection url from the datasource declaration. Did you try to set the encoding on the connection url?

jdbc:mysql://localhost:3306/yourDB?useUnicode=true&characterEncoding=UTF-8

I can't test for oracle, but for mysql it solves the problem.

笑咖 2025-01-09 05:30:44

正如评论中所述,我意识到这个问题没有意义,因为数据库连接实际上没有问题。正如元讨论我正在解释这个作为答案。

As stated in the comments I realized that the question does not make sense since there actually is no problem in the DB connection. As suggested in a meta-discussion I am explaining this as an answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文