Reading a CLOB from Oracle DB after the DB connection is closed?

You should be able to simply use getString() on that column.

Up vote 2 down vote favorite share g+ share fb share tw.

In one of the Java classes I am reviewing I see the following code private oracle.sql. CLOB getCLOB() { oracle.sql. CLOB xmlDocument = null; CallableStatement cstmt = null; ResultSet resultSet = null; Connection connection = null; try { connection = Persistence.getConnection(); cstmt = connection.

PrepareCall("{call pkg. Proc(?,? )}"); cstmt.

RegisterOutParameter(1, OracleTypes. CURSOR); cstmt. SetString(2, id); cstmt.execute(); resultSet = (ResultSet)cstmt.

GetObject(1); if (resultSet.next()) { xmlDocument = ((OracleResultSet) resultSet). GetCLOB(1); } } finally { Persistence. CloseAll(resultSet, cstmt, connection); } return xmlDocument; } The oracle.sql.

CLOB that is returned by getCLOB() is read in another method: private void anotherMethod() { ... oracle.sql. CLOB xmlDocument = getCLOB(); clobLength = xmlDocument.length(); chunkSize = xmlDocument.getChunkSize(); textBuffer = new charchunkSize; for (int position = 1; position Write(textBuffer, 0, charsRead); } ... } I am new to this project and the folks here say this code is working. I don't understand how we can read a CLOB (which, in my understanding, is a reference) after the underlying database connection is closed.

What am I missing? EDIT: Another point to note is that this code is running in an app server. Persistence.getConnection() gets the connection from a data source (most probably with a connection pool).

I wonder if the database connection is used after it is returned to the connection pool. EDIT2: Using the connection after it was returned to the pool might not be the cause. The app server is Oracle's Glassfish server Websphere and I am hoping they would guard against such usage.

Java oracle jdbc link|improve this question edited Feb 7 '11 at 12:49 asked Feb 3 '11 at 12:26askullhead4571513 67% accept rate.

You should be able to simply use getString() on that column. The current drivers do not require the use of the CLOB interface anymore. (at least it works for me with regular SELECT statements).

JDBC driver prefetches LOBs selected into a result set. Read API can use prefetch buffers without connection. Buffer size specified by oracle.jdbc.

DefaultLobPrefetchSize parameter with default 4000.

1 A related link - download.oracle.com/docs/cd/E16338_01/ap... – askullhead Feb 3 '11 at 13:54 As result this implementation must fail on CLOBs with length more than 4000 (if defaults are used) – Lev Khomich Feb 3 '11 at 14:37.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions