Skip to Main Content

Java Database Connectivity (JDBC)

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!

Java Unicode String to Clob conversion error

4068Nov 23 2005 — edited Nov 29 2005
I'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;
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 27 2005
Added on Nov 23 2005
5 comments
5,153 views