Java Guy
Java Guy

Reputation: 3441

NVARCHAR in JDK 1.5

I have couple of fields in oracle which is NVARCHAR and I am using Java 1.5. If I read those values as string is that okay or is there a better approach for reading columns with NVARCHAR?

Upvotes: 0

Views: 1210

Answers (1)

WhiteFang34
WhiteFang34

Reputation: 72049

Assuming you have a ResultSet named rs then this is appropriate for NVARCHAR:

String myColumn = rs.getString("my_column");

See Globalization Support for JDBC Drivers:

Oracle JDBC drivers provide globalization support by allowing you to retrieve data from or insert data into columns of the SQL CHAR and NCHAR datatypes of an Oracle9i database. Because Java strings are encoded as UTF-16 (16-bit Unicode) for JDBC programs, the target character set on the client is always UTF-16. For data stored in the CHAR, VARCHAR2, LONG, and CLOB datatypes, JDBC transparently converts the data from the database character set to UTF-16. For Unicode data stored in the NCHAR, NVARCHAR2, and NCLOB datatypes, JDBC transparently converts the data from the national character set to UTF-16.

Upvotes: 2

Related Questions