I searched for the Oracle vendor JDBC driver (ojdbc6.jar) for Oracle Database here
I found the demo.zip file here
I unzipped it and greased the source for clob and blob.
There is a file TemporaryLobJDBC40.java
There is a sample where temporary clob and blob are created, then filled with some data, then inserted into the table through a prepared statement (parameterized INSERT).
Then the statement is executed, closed, temp clob and blob are released and the transaction is completed.
The author then iterates over the rows of the table, creating constant blob / clobs and assigning them the objects returned from getClob (), getBlob () and uploading the contents to the stream.
Permanent drops are never released. I assume that after each iteration, when objects go beyond the scope, the garbage collector automatically releases these objects.
After the last iteration, the last two Blob / Clob objects are not explicitly freed, but are implicitly cleared by the garbage collector (when it decides to start), their scope ends with the last iteration. (after})
Personally, I would do the cleaning explicitly, but to each his own. This demo shows that you can do it anyway.
Here's the code (TemporaryLobJDBC40.java):
import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Blob; import java.sql.Clob; class TemporaryLobJDBC40 { public static void main (String args []) throws Exception { Connection conn = DemoConnectionFactory.getHRConnection( args ); LobExample.createSchemaObjects( conn ); Blob tempBlob = conn.createBlob(); Clob tempClob = conn.createClob(); System.out.println ("tempBlob.isTemporary()="+ ((oracle.sql.BLOB)tempBlob).isTemporary()); System.out.println ("tempClob.isTemporary()="+ ((oracle.sql.CLOB)tempClob).isTemporary()); LobExample.fill(tempBlob, 100L); LobExample.fill(tempClob, 100L); String insertSql = "insert into jdbc_demo_lob_table values ( ?, ?, ? )"; PreparedStatement pstmt = conn.prepareStatement( insertSql ); pstmt.setString( 1, "one" ); pstmt.setBlob( 2, tempBlob ); pstmt.setClob( 3, tempClob ); pstmt.execute(); pstmt.close(); tempBlob.free(); tempClob.free(); conn.commit(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery( "select b, c from jdbc_demo_lob_table" ); while( rs.next() ) { Blob permanentBlob = rs.getBlob(1); Clob permanentClob = rs.getClob(2); System.out.println ("permanentBlob.isTemporary()="+ ((oracle.sql.BLOB)permanentBlob).isTemporary()); System.out.println ("permanentClob.isTemporary()="+ ((oracle.sql.CLOB)permanentClob).isTemporary()); LobExample.dump(permanentBlob); LobExample.dump(permanentClob); } rs.close(); stmt.close(); conn.close(); } }
user78706
source share