my dog learned polymorphism*
The moose likes JDBC and the fly likes Store Java Object in Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Store Java Object in Database" Watch "Store Java Object in Database" New topic

Store Java Object in Database

Parshuram Walunjkar

Joined: Jul 25, 2001
Posts: 8
Hi All,
I want to store java Object in oracle database .
My case was like sometime object is Vector type or sometype it is HashMap Type so how can I store that object in database.
Please help me,
Regards and thanks
Parshuram Walunjkar
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

I have pretty strong feelings on this, and I believe Objects have no place in a database.
Have a look at this thread where we are looking at Object to Relational mappings.
SJ Adnams
Ranch Hand

Joined: Sep 28, 2001
Posts: 925
depends how long it's gonna be there?
appservers serialize sessions to the database all the time. if your just dumping it in the database for later processing then i guess it's fine just to serialise the object:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream os = new ObjectOutputStream(bos);
os.writeObject(<your type> ;
then send bos.toByteArray() to the database.
However, like Dave says it's not a great idea if the data is gonna hang around for more than a software lifecycle. Whats the application?
I agree. Here's the link:
subject: Store Java Object in Database
Similar Threads
How to store SecretKey in database?
Selection of datatype for storing images
how to store a Java Object directly in to a database table
file selected by JFileChooser and storing that image file in ms-access
storing image file in ms-access using jdbc