Quote:
|
Originally Posted by parthasarathi
Hi,
I want to insert java objects into Database without spliting into columns. An Example will help to elucidate my problem.
I have defined a User defined Structure in DB2. Let this be Employee with
CREATE TYPE PERSON_T AS (
Name VARCHAR(20),
Age INT
) REF USING VARCHAR(13) FOR BIT DATA MODE DB2SQL;
CREATE TABLE PERSON OF PERSON_T (ref is oid user generated);
Now, from my java program, after geting the Connection object, I wish to insert an object corresponding to PERSON_T.
My requirement is that I don't want to execute a typical RDBMS insert where we give the column values in the value clause.
Can I insert the whole object into the table without bothering about the individual column or attribute.
Similarly, can I retrieve the entire object in my java program via the select clause ?
Thanks in advance.
Partha.
|
There are tools that do OR mapping for you, so you send the object to it and it has the logic to shred it into relational tables. An example is Oracle's Toplink.
Another option is to serialize the object, but that's not usually desirable...
ie.:
String myObj = "test";
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(byteStream);
oos.writeObject(myObj);
oos.close();
byte[] theBytes = byteStream.toByteArray();
Then you could store that byte array in the database as bit data.