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!

Sample Java code to write to java.sql.Clob in 12c

user12099954Jan 19 2016 — edited Jan 21 2016

In Oracle 12c the CLOB class has been deprecated in ojdbc7.jar.  I have a number of instances where I'm using oracle.sql.CLOB.getBufferSize() to transfer data from an InputStream to the CLOB like so:

               int size = ((CLOB) emptyClob).getBufferSize();

               byte[] cbuffer = new byte[size];

                // Read a chunk of data from the input stream, and write the

                // chunk into the Clob output stream. Repeat till content has been

                // fully read.

                int nread = -1;

                while ((nread = contentStream.read(cbuffer)) != -1) {

                    clobWriter.write(cbuffer, 0, nread);

                }

The API for the oracle.sql.CLOB class says to use the standard java.sql.Clob, and no that fetching chunks is no longer necessary since it's handled internally.  However, it's not clear to me how to implement this, and the JDBC Developers guide doesn't provide any examples.

Can someone provide some sample code that doesn't use the deprecated class?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 18 2016
Added on Jan 19 2016
3 comments
2,380 views