Copying Oracle BLOB data from one database to another
Hi,
My application inserts record consisting of a BLOB data into the following table in a Oracle database, say, DB1.
Table name : DB1_Table1
Columns:
DB1_Table1_Id NUMBER(15) NOT NULL
DB1_Table1_Blob BLOB
After the record has been successfully in DB1_Table1, I read the data from it and insert into the following table in another Oracle database, say, DB2, through a Java program.
Table name: DB2_Table2
Columns:
DB2_Table2_Id NUMBER(15) NOT NULL
DB2_Table2_Blob BLOB
The data is also inserted successfully in the above table.
When I try to read the BLOB data from DB2_Table2 through Java program, it shows me the following error :-
"java.io.StreamCorruptedException: InputStream does not contain serialized object".
Below is the part of the code for inserting record into DB2_Table2:
publicvoid insertIntoDB2_Table2(TestObject testItem)throws Exception
{
Connection conn =null;
Statement stmt =null;
ResultSet rs =null;
try
{
long uniqueId = testItem.getId();
conn = getConnection();
conn.setAutoCommit(false);
String sql ="INSERT INTO DB2_Table2 (DB2_Table2_Id, DB2_Table2_Blob) VALUES ("+uniqueId+", empty_blob())";
stmt = conn.createStatement();
stmt.executeUpdate(sql);
sql ="SELECT DB2_Table2_Blob FROM some_table WHERE DB2_Table2_Id = "+uniqueId;
rs = stmt.executeQuery(sql);
if(rs.next())
{
oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("DB2_Table2_Blob");
java.io.OutputStream out = blob.getBinaryOutputStream();
out.write(testItem.getBinaryData());// testItem.getBinaryData returns byte[]
}
conn.commit();
}
catch(Exception ex)
{
try
{
conn.rollback();
}
catch(Exception ex1)
{
ex1.printStackTrace();
}
ex.printStackTrace();
}
finally
{
try
{
if(rs!=null)
rs.close();
if(stmt!=null)
stmt.close();
if(conn!=null)
conn.close();
}
catch(Exception rx)
{
rx.printStackTrace();
}
}
}
Anybody please help to resolve this issue.
Regards,
Buddhadeb

