• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Ankur Saxena
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thks Jeff for ur kind suggestion,

I did the same ,but before ur reply and it is working fine.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic