You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by bruehlicke <br...@gmail.com> on 2008/02/07 22:04:00 UTC
Newbe: JAVA_OBJECT best type to store as ?
Any example out there for storing a java "Properties" object ?
1) What type shall the Table Column have ? BLOB ? CLOB ?
2) Any example of how to do this ?
My assumption until now is that I have to create a BLOB and serialize and
de-serialize the "Properties" object. The latest I found on this was from
Bernt http://www.mail-archive.com/derby-user@db.apache.org/msg06658.html.
So I just need confirmation on the Column type I should choose.
You need to serialize the object. One way of doing it is like this:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(item);
oos.close();
ps.setBytes(1, bos.toByteArray());
An vice versa when you retrive the object
B-)
Re: Newbe: JAVA_OBJECT best type to store as ?
Posted by bruehlicke <br...@gmail.com>.
Ahhhhhhh WONDERFUL
takk skal du ha !
B-)
On Feb 8, 2008 2:20 AM, Knut Anders Hatlen <Kn...@sun.com> wrote:
> bruehlicke <br...@gmail.com> writes:
>
> > Any example out there for storing a java "Properties" object ?
> >
> > 1) What type shall the Table Column have ? BLOB ? CLOB ?
> >
> > 2) Any example of how to do this ?
> >
> > My assumption until now is that I have to create a BLOB and serialize
> and
> > de-serialize the "Properties" object. The latest I found on this was
> from
> > Bernt http://www.mail-archive.com/derby-user@db.apache.org/msg06658.html
> .
> > So I just need confirmation on the Column type I should choose.
> >
> > You need to serialize the object. One way of doing it is like this:
> >
> > ByteArrayOutputStream bos = new ByteArrayOutputStream();
> > ObjectOutputStream oos = new ObjectOutputStream(bos);
> > oos.writeObject(item);
> > oos.close();
> > ps.setBytes(1, bos.toByteArray());
> >
> > An vice versa when you retrive the object
>
> Yes, that's the way to store a Java object in Derby, unless you use some
> kind of object persistence or object-relational mapping framework on top
> of Derby, and BLOB is the data type you need.
>
> For Properties objects, you could alternatively use a CLOB/VARCHAR,
> since Properties contains its own serialization method that outputs
> plain text. The advantage of using a CLOB/VARCHAR instead of a BLOB, is
> that it is easier to inspect the contents of the object in tools like
> ij.
>
> Then you'd do something like this (untested):
>
> StringWriter sw = new StringWriter();
> properties.store(sw, null);
> ps.setString(1, sw.toString());
>
> and to restore the object
>
> Reader reader = rs.getCharacterStream(1);
> Properties properties = new Properties();
> properties.load(reader);
>
> --
> Knut Anders
>
Re: Newbe: JAVA_OBJECT best type to store as ?
Posted by Knut Anders Hatlen <Kn...@Sun.COM>.
bruehlicke <br...@gmail.com> writes:
> Any example out there for storing a java "Properties" object ?
>
> 1) What type shall the Table Column have ? BLOB ? CLOB ?
>
> 2) Any example of how to do this ?
>
> My assumption until now is that I have to create a BLOB and serialize and
> de-serialize the "Properties" object. The latest I found on this was from
> Bernt http://www.mail-archive.com/derby-user@db.apache.org/msg06658.html.
> So I just need confirmation on the Column type I should choose.
>
> You need to serialize the object. One way of doing it is like this:
>
> ByteArrayOutputStream bos = new ByteArrayOutputStream();
> ObjectOutputStream oos = new ObjectOutputStream(bos);
> oos.writeObject(item);
> oos.close();
> ps.setBytes(1, bos.toByteArray());
>
> An vice versa when you retrive the object
Yes, that's the way to store a Java object in Derby, unless you use some
kind of object persistence or object-relational mapping framework on top
of Derby, and BLOB is the data type you need.
For Properties objects, you could alternatively use a CLOB/VARCHAR,
since Properties contains its own serialization method that outputs
plain text. The advantage of using a CLOB/VARCHAR instead of a BLOB, is
that it is easier to inspect the contents of the object in tools like
ij.
Then you'd do something like this (untested):
StringWriter sw = new StringWriter();
properties.store(sw, null);
ps.setString(1, sw.toString());
and to restore the object
Reader reader = rs.getCharacterStream(1);
Properties properties = new Properties();
properties.load(reader);
--
Knut Anders
Re: Newbe: JAVA_OBJECT best type to store as ?
Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
---------------------------------------------------------------------------
HARBOR: http://coolharbor.100free.com/index.htm
The most powerful application server on earth.
The only real POJO Application Server.
Making the Java dream come true.
---------------------------------------------------------------------------
----- Original Message -----
From: bruehlicke
To: derby-user@db.apache.org
Sent: Thursday, February 07, 2008 11:04 PM
Subject: Newbe: JAVA_OBJECT best type to store as ?
Any example out there for storing a java "Properties" object ?
1) What type shall the Table Column have ? BLOB ? CLOB ?
2) Any example of how to do this ?
My assumption until now is that I have to create a BLOB and serialize and
de-serialize the "Properties" object. The latest I found on this was from
Bernt http://www.mail-archive.com/derby-user@db.apache.org/msg06658.html.
So I just need confirmation on the Column type I should choose.
=================================
Go to this link
http://coolharbor.100free.com/demo_dB_Pool.htm
Ignore the fact that the code its for an Application server.
Its a POJO Application server so it runs normal Java applications
On that page you will find all the source, it was originally written for
Derby
The little demo lib source is there as well, it does everything from dB
pooling, to serialization (with example)
to something called POJO persistance, which has a different view on
Hibernate JPA way
Also transactions in plain old SQL... and lots of other stuff
And if you like... you can use the POJO server to put the application on a
network, or the web, or start it from a desktop.... or or or
The sample was written for embedded apps....
Enjoy...
=================================
You need to serialize the object. One way of doing it is like this:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(item);
oos.close(); ps.setBytes(1, bos.toByteArray());An vice versa
when you retrive the object
B-)