Ahhhhhhh WONDERFUL takk skal du ha !
B-) On Feb 8, 2008 2:20 AM, Knut Anders Hatlen <[EMAIL PROTECTED]> wrote: > bruehlicke <[EMAIL PROTECTED]> 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/[email protected]/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 >
