It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes storing objects in a 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 "storing objects in a database" Watch "storing objects in a database" New topic

storing objects in a database

Chris Patton

Joined: Jun 12, 2000
Posts: 7
I'm relatively new to databases, but I think I've mastered the basic concepts and I was wondering how I would store a java object in a database. As far as I understand, I would just have to serialize it and store it int the database as a blob, but I don't exactly know how i would do this code-wise. I would be eternally grateful if someone could help me out.
- Chris
Milind Kulkarni
Ranch Hand

Joined: Jun 01, 2000
Posts: 146
Hi Chris,
Here is how I would do it:
Blob binobj = rs.getBlob("BINOBJ");
PreparedStatement pstmt = con.prepareStatement( "UPDATE MYTABLE SET BINARYOBJ = ?");
pstmt.setBlob(1, binobj);
Hope this helps!

[This message has been edited by Milind Kulkarni (edited August 19, 2000).]
I agree. Here's the link:
subject: storing objects in a database
It's not a secret anymore!