Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Storing a Java Object in Oracle [code] Blob [/code]

 
Sri Ram
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you tell me how to store and Retrieve a Java Object using a Oracle ???
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typically, you might serialise to a ByteArrayOutputStream then write the byte array to the BLOB. To read, get the byte array from the BLOB then deserialise from a ByteArrayInputStream based on that array.

If you don't know how to serialise/deserialise to/from streams, read up on Java Serialisation, independent of databases.

As a possible optimisation, note that Blob objects have built-in InputStream and OutputStream functionality, from Java 1.4 onwards.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Original Poster sent me a private message asking for code for this. UseTheForumNotEmail

No need for me to go writing example code. Sun's own ought to suffice. See Sun's BLOB example code.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34378
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
Thanks for bringing it back to the forums!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic