• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Store Java Object to DB2 Database

 
Adam Tao
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If I want to store a Java object (for example an Array object) to the Db2
database, how can I get such a function? Please advice.
Thanks a lot!
 
Amy Smith
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like this question! Not that I have ever done this.
What about writing your own method to store the results of serialize in a table? BLOB comes to mind...
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would be the standard way, serialise the object then write to the DB a s a BLOB. I guess another option would be an Object Database...
The bigger question is why you would want to store (I'm assuming) object instances in the database. In practice, it tends to reduce separation of application layers since it counts as managing business logic in the persistence mechanism.
Personally I always try to find a solution that does not require writing java objects, classes or even images to the DB.
Dave
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"AT",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Thanks.
Dave
 
Adam Tao
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for that, I updated the displayed name.
I have stored serialized object to the db as BLOB, I know it is not a good way to do it, but sometimes the business logic is very complicated, if we store it as object, it will bw very easy to do it.
Thanks.
Adam
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Except that if you ever alter the class you're going to have a hell of a time getting the data back out since the serialisation and deserialisation processes will be different...
Oh, and your name still isn't correct. It has to be First-name Last-name. I'm pretty sure we don't accept 'TTJ' as a last name
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic