wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes Can I write the object to Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Can I write the object to Database" Watch "Can I write the object to Database" New topic
Author

Can I write the object to Database

Huzefa Zohaib
Ranch Hand

Joined: Nov 21, 2001
Posts: 40
Can I write the object to Database
I want to write the object in database can I do it by converting it to
set of bytes or strings or otherwise.
Jacob George
Ranch Hand

Joined: Jun 26, 2001
Posts: 46
Originally posted by Huzefa Zohaib:
Can I write the object to Database
I want to write the object in database can I do it by converting it to
set of bytes or strings or otherwise.

Hi,
You may do so using setObject() method in PreparedStatement, provided u'r object has an equivalent SQL Type mapping(Please refer the java doc for more details). Otherwise, you have to convert your object into byte[] and then set the same using setBytes() method. In the code snippet given below, I have assumed that the object to be stored in database implements serializable/externalizable interface.

This will insert the object into database. While retrieving the object, you have to do the reverse procedure; take the byte[]; then create a ByteArrayInputStream; ObjectInputStream on top of ByteArrayInputStream and then call readObject().
regards Jacob
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Can I write the object to Database
 
jQuery in Action, 3rd edition