This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JDBC and the fly likes how to store a Java Object directly in to a database table  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to store a Java Object directly in to a database table  " Watch "how to store a Java Object directly in to a database table  " New topic
Author

how to store a Java Object directly in to a database table

Ankur Saxena
Greenhorn

Joined: Dec 28, 2005
Posts: 11
Hi Every body,

I wanna Store a Java Object directly in to a database table. For doing so I want to know that which data type should I take for a database table column and how it is possible to store a java object in to a Database table. If any body has idea, plz reply .

Thks in Advance

Regards

Ankur Saxena
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
If you serialize an object, that essentially turns it into a byte[] (or data written to an OutputStream), and then you can use the SQL type BLOB. How do you insert a BLOB? Google for that. If you are using Hibernate (judging from your crosspost) this is especially easy to do. Your POJO could make methods that are backed by the same data:


There is no emoticon for what I am feeling!
Ankur Saxena
Greenhorn

Joined: Dec 28, 2005
Posts: 11
Thks Jeff for ur kind suggestion,

I did the same ,but before ur reply and it is working fine.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Just to provide an alternate view: Don't. We very rarely put java objects into the DB (I can think of two instances) you're far better of using an ORM toll and mapping the object to a table.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to store a Java Object directly in to a database table