Oracle DB、Glassfish、Hibernate 和字符编码
我们有一个使用 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 Glassfishadding 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如使用 NVARCAR 对原始问题的评论中所讨论的,添加到 Hibernate 配置文件中的以下行似乎有效。
它对我有用。
As discussed in the comments to the original question using NVARCAR and the following line added to the Hibernate configuration file seems to work.
It did for me.
您还没有在数据源声明中提及任何有关连接 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.
正如评论中所述,我意识到这个问题没有意义,因为数据库连接实际上没有问题。正如元讨论我正在解释这个作为答案。
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.