/*
Code revised from
JDBC Recipes: A Problem-Solution Approach
# By Mahmoud Parsian
# ISBN: 1-59059-520-3
# 664 pp.
# Published: Sep 2005
publisher: apress.com
*/
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import oracle.sql.BLOB;
/****
CREATE TABLE java_objects (object_id NUMBER, object_name varchar(128), object_value BLOB DEFAULT empty_blob(), primary key (object_id));
SQL> desc java_objects;
Name Null? Type
----------------------------------------- -------- ----------------------------
OBJECT_ID NOT NULL NUMBER
OBJECT_NAME VARCHAR2(128)
OBJECT_VALUE BLOB
SQL> select SEQUENCE_NAME, MIN_VALUE, MAX_VALUE, INCREMENT_BY, LAST_NUMBER from user_sequences;
SEQUENCE_NAME MIN_VALUE MAX_VALUE INCREMENT_BY LAST_NUMBER
------------------------------ ---------- ---------- ------------ -----------
ID_SEQ 1 1.0000E+27 1 21
JAVA_OBJECT_SEQUENCE 1 1.0000E+27 1 1
*/
public class Main {
public static void main(String[] args) throws Exception {
String WRITE_OBJECT_SQL = "BEGIN "
+ " INSERT INTO java_objects(object_id, object_name, object_value) "
+ " VALUES (?, ?, empty_blob()) " + " RETURN object_value INTO ?; " + "END;";
String READ_OBJECT_SQL = "SELECT object_value FROM java_objects WHERE object_id = ?";
Connection conn = getOracleConnection();
conn.setAutoCommit(false);
List