db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Hillegas <Richard.Hille...@Sun.COM>
Subject Re: Storing Java Objects in a table
Date Wed, 26 Oct 2005 21:35:19 GMT
Hi Islay,

It is true that old versions of Cloudscape let you declare a column to 
be a Serializable type. This functionality was removed from Derby 
because the syntax was non-standard. Most of the machinery to support 
this useful feature, however, still exists. I have logged enhancement 
request 651 to track the re-enabling of this functionality modulo 
agreement on some standard syntax.

That doesn't help you right now, though. As a crude workaround, declare 
a column of some binary or char type (including blob and clob).  Then 
serialize your object to a byte array or io stream in your applicaton. 
Then write this array or stream to the column yourself using methods on 
PreparedStatement like setBytes() or setBinaryStream().

I recommend that you make your class implement java.io.Externalizable. 
That way you can write your own deserialization logic to handle version 
upgrades of your class. Don't rely on java.io.Serializable; it doesn't 
handle versioning and  isn't appropriate for persisting data; as soon as 
you make a change to your class, you won't be able to deserialize old 
versions.

I'm happy to give you more advice if this is too cryptic.

Regards,
-Rick

Islay Symonette wrote:

> Hello,
> Sorry to bother you with such a trivial question.
>
> I am trying to create a table with one of the columns storing a java 
> object. The sql statement I have is:
>
> CREATE TABLE StoreObject (objectID INT, object MyJavaObject);
>
> And recieved this:
> ERROR 42X01: Syntax error: Encountered "" at line 1, column 46.
>
> I understand from the manuals that inorder to load a java class, you 
> have to store it in a jar file.
> I created a jar containing the class for the object using eclipse. 
> Location: C:\Derby\testingjar.jar
> Then using ij I typed (after connecting to the database):
>
> CALL SQLJ.install_jar('c:\derby\testingjar.jar', 'APP.TestLogic', 0);
> 0 rows inserted/updated/deleted
> CALL 
> SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.classpath', 
> 'APP.TestLogic');
> 0 rows inserted/updated/deleted
>
> I'm afraid I don't know where I've gone wrong, any help would be 
> greatly appreciated.
> Thanks,
> Islay
>
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today it's 
> FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
>


Mime
View raw message