ImageIcon in Database

Hi,

I am trying to store an ImageIcon in a database:

inserting the Icon works fine using this code:

(rs is a ResultSet)

rs.updateObject("PICTURE",new ImageIcon("D:/test.jpg"));

rs.insertRow();

when I try to retrieve the icon using:

ImageIcon icon = ((ImageIcon) rs.getObject("PICTURE"));

I get a ClassCastException:

java.lang.ClassCastException: [B cannot be cast to javax.swing.ImageIcon

Is this a problem with my code, or could this be a jdbc Driver problem?

I am using the relatively new H2 Database (http://www.h2database.com/html/frame.html)

Thanks

Bjoern

[758 byte] By [bjbaa] at [2007-11-27 4:51:13]
# 1
You're trying to cast a byte[] to an ImageIcon object. This won't work as ImageIcon is likely not a subclass of byte[].You need to check if this ImageIcon object has a constructor or a setter to pass a byte[] along it, so that you can use it.
BalusCa at 2007-7-12 10:04:53 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Does this mean, that updateObject(..) serializes the Object to a byte[] and

rs.getObject(...)

retieves only a byte[], but not a deserialized original Object?

What I mean, if I do a

writeObject(icon);

and later a

(ImageIcon) readObject();

on a ObjectOutput / ObjectInputStream, I don't get a ClassCastException is this different in JDBC?

Thanks

bjbaa at 2007-7-12 10:04:53 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Sorry, solved the problemI had to submit the ImageIcons via a PreparedStatement to the database. Then reading it via getObject(...) resulted in an ImageIcon Object.Seems to be a quirk in the H2 database...Thanks for the repliesBjoern
bjbaa at 2007-7-12 10:04:53 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...