Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to store Object in MySQL database

I have a variable in java which return type is Object(java.lang.Object). I want to store this variable value in MySQL database without casting in any other primitive data type. Is there any data type available in MySQL related to Object?

like image 898
kandarp Avatar asked Apr 30 '10 19:04

kandarp


2 Answers

You can use a BLOB to store the raw data, but otherwise no, MySQL does not have a datatype specifically for a java object.

As a side note: You probably shouldn't be storing a raw object into the database, that kind of prevents you from doing any sort of queries on it.

like image 139
Mitch Dempsey Avatar answered Oct 14 '22 05:10

Mitch Dempsey


You must serialize the Object anyway, so you could serialize to XML or JSON aswell. A human readable storage form is what I would prefer. Have a look at Xstream for example. A great, threadsafe tool for marshalling/unmarshalling.

I assume of course, that your Object is a Bean/POJO.

like image 3
rompetroll Avatar answered Oct 14 '22 05:10

rompetroll