对 Oracle 的 JDBC 调用返回 3 个问号

发布于 2025-01-07 22:36:19 字数 665 浏览 0 评论 0原文

我使用 JDBCTemplate 调用 Oracle 存储过程,该过程具有 STRUCT 的输入/输出参数。该结构上的字段之一是 VARCHAR,它根据存储过程逻辑进行更新。然而,当从调用返回时,它只包含三个问号 - '???'。这可能是 Riddler 的作品,但听起来更像是字符编码问题。

这工作正常,直到我们将数据库切换到字符编码为 WE8ISO8859P15 (ISO8859) 的数据库,这是通过执行以下操作检索的:

SELECT NLS_CHARACTERSET FROM NLS_DATABASE_PARAMETERS

以前工作的字符集是 WE8MSWIN1252 (MSWIN-1252),工作正常。所以我猜测这归因于字符集问题,尽管我有点谨慎,因为无论应返回多少文本,它总是只返回 3 个问号。

据我了解,底层 JDBC 驱动程序 (jdbc:oracle:thin) 会自动执行所有字符编码,并将数据库字符集转换为 UTF-16(Java 字符编码),但似乎这并没有发生。我使用 StoredProcedure 类(Spring 的一部分)来调用 StoredProcedure。

我还尝试将 orai18n.jar 添加到类路径中,但没有成功。然而,考虑到 ISO-8859 是一个非常标准的字符集,这似乎真的很不寻常,所以我可能走错了路。

任何帮助将不胜感激。

I do a call to an oracle stored procedure using JDBCTemplate which has an in/out parameter of STRUCT. One of the fields on this struct is a VARCHAR which gets updated depending on the stored procedure logic. However when this is returned from the call it just contains three question marks - '???'. This is possibly the work of the Riddler but it sounds more like a char encoding issue.

This worked fine until we switched databases to a database that had a character encoding of WE8ISO8859P15 (ISO8859) this was retrieved by doing:

SELECT NLS_CHARACTERSET FROM NLS_DATABASE_PARAMETERS

The previously working character set was WE8MSWIN1252 (MSWIN-1252) which works fine. So I'm guessing it's down to a char set issue although I'm slightly wary as it always returns just 3 question marks regardless of how much text should be returned.

As far as I understand the underlying JDBC driver (jdbc:oracle:thin) does all the character encoding automatically and converts the database char set to UTF-16 (Java char encoding) however it appears this is not happening. I'm using the StoredProcedure class (part of Spring) to call the StoredProcedure.

I've also tried adding the orai18n.jar to the classpath but with no success. However it seems really unusual considering ISO-8859 is a pretty standard charset so I might be going down the wrong path.

Any help would be greatly appreciated.

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

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

发布评论

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

评论(1

红衣飘飘貌似仙 2025-01-14 22:36:19

这是一个字符编码问题,因为数据库字符编码存储为 ISO-8859-15 - 该标准的第 15 版导致了所有问题,本质上是添加了欧元符号。我们用来通过 JDBC 连接的 oracle 驱动程序根本无法完成从 ISO-8859-15 到 Java 的 UTF-16 的转换。

恢复到 ISO-8859-1 或更改为数据库上的 UTF-8 编码(更好)可以解决此问题。将 orai18n jar 添加到类路径可能可以解决此问题,但由于没有现成的 OSGI 包,因此这并不容易完成。我的建议是根本不要理会 Oracle 数据库。

This was a char encoding issue due to the database character encoding being stored as ISO-8859-15 - version 15 of this standard was causing all the problems which is essentially the addition of the Euro symbol. The oracle driver we were using to connect via JDBC simply couldn't do the conversion from ISO-8859-15 to Java's UTF-16.

Reverting back to ISO-8859-1 or changing to UTF-8 encoding on the database (better) resolves this. It's possible that adding the orai18n jar to the classpath may resolve this but as there is no readily availble OSGI bundle for this it wasn't as easily done. My recommendation is don't bother with Oracle databases at all.

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