Java Unicode String to Clob conversion error
4068Nov 23 2005 — edited Nov 29 2005I'm facing a problem when converting a java string (which is unicode) to a oracle.sql.CLOB.
The string contains some multibyte characters such as ć, â, etc.
The string can be written perfectly to System.out with those characters, but when I try to append this string to an oracle CLOB I'm getting an exception.
The piece of code that performs this conversion is:
private CLOB getCLOB(String xmlData, Connection conn) throws SQLException
{
CLOB tempClob = null;
try
{
// If the temporary CLOB has not yet been created, create new
tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);
// Open the temporary CLOB in readwrite mode to enable writing
tempClob.open(CLOB.MODE_READWRITE);
// Get the output stream to write
Writer tempClobWriter = tempClob.getCharacterOutputStream();
// Write the data into the temporary CLOB
tempClobWriter.write(xmlData);
// Flush and close the stream
tempClobWriter.flush();
tempClobWriter.close();
// Close the temporary CLOB
tempClob.close();
}
catch(SQLException sqlexp)
{
tempClob.freeTemporary();
sqlexp.printStackTrace();
}
catch(Exception exp)
{
tempClob.freeTemporary();
exp.printStackTrace();
}
return tempClob;
}