JDBC program is inserting ¿ in NVARCHAR2 column.
724313Sep 24 2009 — edited Sep 24 2009I 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