Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 69547 invoked from network); 8 Feb 2008 08:22:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Feb 2008 08:22:02 -0000 Received: (qmail 81480 invoked by uid 500); 8 Feb 2008 08:21:53 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 81459 invoked by uid 500); 8 Feb 2008 08:21:53 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 81448 invoked by uid 99); 8 Feb 2008 08:21:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Feb 2008 00:21:53 -0800 X-ASF-Spam-Status: No, hits=-1.0 required=10.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [192.18.6.21] (HELO gmp-eb-mail-1.sun.com) (192.18.6.21) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 08 Feb 2008 08:21:21 +0000 Received: from fe-emea-10.sun.com (gmp-eb-lb-2-fe3.eu.sun.com [192.18.6.12]) by gmp-eb-mail-1.sun.com (8.13.7+Sun/8.12.9) with ESMTP id m188LR2p024913 for ; Fri, 8 Feb 2008 08:21:27 GMT Received: from conversion-daemon.fe-emea-10.sun.com by fe-emea-10.sun.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) id <0JVW00K01V2IRY00@fe-emea-10.sun.com> (original mail from Knut.Hatlen@Sun.COM) for derby-user@db.apache.org; Fri, 08 Feb 2008 08:21:27 +0000 (GMT) Received: from localhost ([193.71.105.147]) by fe-emea-10.sun.com (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) with ESMTPSA id <0JVW00G82V7OQU20@fe-emea-10.sun.com> for derby-user@db.apache.org; Fri, 08 Feb 2008 08:21:25 +0000 (GMT) Date: Fri, 08 Feb 2008 09:20:55 +0100 From: Knut Anders Hatlen Subject: Re: Newbe: JAVA_OBJECT best type to store as ? In-reply-to: <6ac05c90802071304x2dc3fcbblf16ebf56ec7ac100@mail.gmail.com> Sender: Knut.Hatlen@Sun.COM To: Derby Discussion Message-id: Organization: Sun Microsystems MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT References: <6ac05c90802071304x2dc3fcbblf16ebf56ec7ac100@mail.gmail.com> User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (usg-unix-v) X-Virus-Checked: Checked by ClamAV on apache.org bruehlicke 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