Subject Re: Data Type Mappings
Author rrokytskyy
Hi,

> When reading a byte[] from the BLOB field can I do the reverse i.e.
> stmt = conn.prepareStatement(queryString);
> rs = stmt.executeQuery();
> if (rs.next()) {
> serializedObject = (SerializedObject) rs.getObject
(colIndex);
> }

No, this will not work. You will get ClassCastException, we do not
deserialize objects. :)

> or do I have to do the following?
> stmt = conn.prepareStatement(queryString);
> rs = stmt.executeQuery();
> if (rs.next()) {
> ObjectInputStream in = new ObjectInputStream(
> new ByteArrayInputStream(rs.getBytes(1)));
> serializedObject = (SerializedObject) in.readObject();
> }

This is the correct approach.

Best regards,
Roman