Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Store Java Object in Database

 
Parshuram Walunjkar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 925
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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> ;
os.flush();
os.close();
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?
Simon
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic