Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JDBC program is inserting ¿ in NVARCHAR2 column.

724313Sep 24 2009 — edited Sep 24 2009
I have a 10.2.0.1 database on a windows XP machine.

The value of NLS_CHARACTERSET is WE8MSWIN1252 and the value of NLS_NCHAR_CHARACTERSET is AL16UTF16.

I have a table with a NVARCHAR2 column. I am using JDBC thin driver to connect to the database. When I am to inserting a japanese character to this column, the value that is getting inserted is ¿ (inverted question mark) instead of the actual Japanese character. Following is the code snippet of my Java program


Class.forName("oracle.jdbc.OracleDriver");
props.put("user", "bcan");
props.put("password","bcan2226");
url = "jdbc:oracle:thin:@myserver:1521:eng";
Connection conn = DriverManager.getConnection(url, props);

String value = "abcdefghi\u7c73"; //\u7c73 is the japanese character
String sql = "insert into I18N VALUES ('" + value + "')";
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);


Can you please let me know why is ¿ getting inserted instead of the japanese character I am trying to insert?

BTW I noticed that if I use PreparedStatement like the following then the proper character gets inserted.

Class.forName("oracle.jdbc.OracleDriver");
props.put("user", "bcan");
props.put("password","bcan2226");
props.put("oracle.jdbc.defaultNChar","true");

url = "jdbc:oracle:thin:@myserver:1521:eng";
Connection conn = DriverManager.getConnection(url, props);

String value ="abcdefghi\u7c73";
String sql = "insert into I18N VALUES (?)";

PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1,value);
stmt.executeUpdate();



Thanks
Sudipta
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 22 2009
Added on Sep 24 2009
5 comments
1,168 views