14

We are building a Java application backed by an Oracle database that we access using JDBC (drivers ojdbc6.jar and orai18n.jar). The database schema stores text columns primarily using the NVARCHAR2 data type.

The JDBC documentation for the JDBC ResultSet says that getNString() is particularly intended for use with the NCHAR, NVARCHAR etc. data types, but at the moment we are only using getString().

This seems to work fine, so I am wondering why I should use getNString() rather than getString(). Is getString() going to start failing if non-ASCII characters are entered, or is the Oracle JDBC driver indifferent as to which method I should use?

EDIT: Seems that it may be database-dependent: SQL Server doesn't seem to mind which you use, depending on the connection parameters. Does anyone have any specific information on Oracle?

4

2 に答える 2

10

アプリケーションでテストを行ったところ、getNString()Java 6、JDBC 6、Oracle JDBC 6 ドライバー、および Oracle 11.1.0.6.0 では不要のようです。私が使用したテスト文字列は、 http://en.wikipedia.org/wiki/Unicodeからコピーした "Δ, Й, ק, ã ã, ๗, あ, 叶, 葉, および 말"でした。

データ アクセスのほとんどは、ストアド プロシージャを介して行われます。Java は、 (抽象化の理由ではなく) setObject()andを介して上記のテスト文字列を正しく設定および取得し、インターフェイスからデータを収集して、期待どおりにインターフェイスに書き戻すことができました。getString()setString()

したがってgetString()、Oracle 11g (上記のリンクの SQL Server など) の Unicode データに対しては問題なく動作するため、getNString().

于 2011-06-22T07:48:12.863 に答える
2

DB がデータ型を使用する場合、NVARCHAR2多言語データを格納するように設計されています。これらの列に Unicode データが格納されていると、プログラムが壊れます。私があなたなら、getNXXX()メソッドに移ります

于 2011-05-05T04:40:57.993 に答える