Serializing large objects as BLOBs to a database
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Dirk_Keller
Posted On:   Wednesday, January 9, 2002 02:25 AM

Serializing large objects (trees, XML-DOMs ...) to a database can be done by BLOBs. When i combine file-streams with ObjectOutputStream/ObjectInputStream and write the BLOB to the database the serialization process works fine. Using PipedInputStream/PipedOutPutStream instead, i get a problem. And ... on the other hand i must not use threads. Here my idea. .... PreparedStatement pstmt = con.prepareStatement(mySqlStr,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); int blobid = 1; // for testing this is "1" pstmt.setInt(1,blobid); try{ // try to write the stream to a BLOB Pipe   More>>

Serializing large objects (trees, XML-DOMs ...) to a database can be done by BLOBs.

When i combine file-streams with ObjectOutputStream/ObjectInputStream and write the BLOB to the database

the serialization process works fine.

Using PipedInputStream/PipedOutPutStream instead, i get a problem.

And ... on the other hand i must not use threads.


Here my idea.

			
....
PreparedStatement pstmt = con.prepareStatement(mySqlStr,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
int blobid = 1; // for testing this is "1"
pstmt.setInt(1,blobid);
try{
// try to write the stream to a BLOB
PipedOutputStream pipeOut = new PipedOutputStream();
PipedInputStream pipeIn = new PipedInputStream(pipeOut);

// the output of ObjectStream goes through the pipe so the result is the input for the PipedInputStream
ObjectOutputStream pout = new ObjectOutputStream(pipeOut);

// the pipedInputStream for the BLOB; 0 = unlimited
// seems this method tries to read the complete stream first in order to replace the second questionmark
// but it does not wait for the ".writeObject()" call
pstmt.setBinaryStream(2,pipeIn,0);

// this will replace the second question mark
// this does not work, (program hangs, looks like a endless loop)
pout.writeObject(myLargeObject);

pout.flush();
pout.close();

}catch (IOException ex){
ex.printStackTrace();
}

int retVal = pstmt.executeUpdate(); // now the blob is written to the database

pstmt.close();
con.close();
.....


Do you know a solution of how to realize this ?


Thanks in advance.

   <<Less

Re: Serializing large objects as BLOBs to a database

Posted By:   Christopher_Schultz  
Posted On:   Wednesday, January 9, 2002 05:58 AM

Why are you trying to use a PipedOutputStream with a JDBC connection?



-chris
About | Sitemap | Contact