Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> NCLOB fields and CLOB.createTemporary does not work
I'm using Oracle 9i, using the latest thin JDBC Java driver. I'm trying
to insert a NCLOB into the database. The recommended way to do this is
to use CLOB.createTemporary() as you can see in the code below. This
code works fine for CLOB fields, but fails with a 'ORA-12704: character
set mismatch' when the field is NCLOB.
Any help with this problem would be appreciated. This code works fine under Oracle 10g, but we cannot force our customers to upgrade just for unicode support.
We're using a unicode character set for the database, but the code fails on non-unicode character set installs as well.
Any help with this would be appreciated.
package nl.ogdsoftware.tas.test;
import java.io.IOException; import java.io.Reader; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;
import oracle.sql.CLOB;
public class OracleNClobProblem {
public static void main(String[] args) throws SQLException, IOException {
Class.forName("oracle.jdbc.driver.OracleDriver"); Connection c =
Statement s = c.createStatement();
s.execute("CREATE TABLE TESTTABLE (nclobcolumn NCLOB)");
PreparedStatement ps = c.prepareStatement("INSERT INTO TESTTABLE (nclobcolumn) VALUES (?)");
CLOB clob = CLOB.createTemporary(c, false, CLOB.DURATION_SESSION);
clob.putChars(1, "0123456789abcdef".toCharArray());
ps.setObject(1, clob);
ps.execute(); /* Fails with: java.sql.SQLException: ORA-12704: character set mismatch */ }
-- John HendrikxReceived on Wed Apr 27 2005 - 05:28:06 CDT