Thread: storing java objects

storing java objects

From
Nathan Gelbard
Date:
Solaris 2.6, Java 1.2, postgresql 6.4.2.

I noticed getObject/setObject functions in the API,
and would like to store java objects in my
psql DB. Is this possible?

how do i define a table that holds java.sql.Types.JAVA.OBJECT s?

Is there any example code laying around to do this?
thanx
natez

Nate Gelbard                         cell: 503.805.1015
Straylight Research               fax : 516.828.8533



Re: [INTERFACES] storing java objects

From
Peter T Mount
Date:
On Wed, 30 Jun 1999, Nathan Gelbard wrote:

> Solaris 2.6, Java 1.2, postgresql 6.4.2.

First, you'll need the 6.5 driver to get it to work with JDK1.2. It will
work with 6.4.2

> I noticed getObject/setObject functions in the API, and would like to
> store java objects in my psql DB. Is this possible?

Yes.

> how do i define a table that holds java.sql.Types.JAVA.OBJECT s?

There's two methods in the API.

1. Define a class that extends postgresql.util.PGObject, then register it  with postgresql.Connection.
  This allows you to implement new datatypes. Take a look at the  postgresql.geom sub-package.

2. Make any of your objects Serialisable. Then call the create() method in  postgresql.util.Serialise. This will create
thenecessary tables for  the object.
 

There's extensive notes on how to do #2 in the source to the
postgresql.util.Serialise class.

> Is there any example code laying around to do this?

I thought I did write an example, but it's not there. I'll go and look for
it.

Peter

--       Peter T Mount peter@retep.org.uk     Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgresJava PDF Generator: http://www.retep.org.uk/pdf