JDBC对Oracle的调用返回3个问号 [英] JDBC Call to Oracle returns 3 question marks

查看:260
本文介绍了JDBC对Oracle的调用返回3个问号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这很好,直到我们将数据库切换到字符编码为WE8ISO8859P15(ISO8859)的数据库为止,可以通过执行以下操作来检索它:

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

以前可以使用的字符集是WE8MSWIN1252(MSWIN-1252),可以正常工作.因此,我猜测这是一个字符集问题,尽管我有点警惕,因为无论返回多少文本,它总是只返回3个问号.

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.

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

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.

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

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.

推荐答案

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

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.

恢复到ISO-8859-1或更改数据库上的UTF-8编码(更好)可以解决此问题.可能将orai18n jar添加到类路径中可能会解决此问题,但是由于没有容易获得的OSGI捆绑软件,因此并非易事.我的建议是完全不理会Oracle数据库.

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.

这篇关于JDBC对Oracle的调用返回3个问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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