3 messages in com.mysql.lists.javaRe: JDBC ResultSet.getObject(int colu...
FromSent OnAttachments
Hidden, Bill07 Oct 2003 07:21 
Mark Matthews07 Oct 2003 07:54 
Hidden, Bill07 Oct 2003 08:11 
Subject:Re: JDBC ResultSet.getObject(int column) returns array of bytes.
From:Mark Matthews (ma@mysql.com)
Date:10/07/2003 07:54:21 AM
List:com.mysql.lists.java

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1

Hidden, Bill wrote:

I'm working with mysql 4.0.15 using mysql-connection-java-3.0.8-stable.

It seems if a column in the result set is one of the following:BINARY, VARBINARY, or LONGVARBINARY ; that is not a serialized object then the returned object is an array of bytes. I think that the returned object should be a java.sql.Blob.

This is a holdover/compatibility issue with pre JDBC-2.0 (which didn't have java.sql.Blob), and is required by the JDBC spec as far as I can tell (the JDBC spec, version 1.2, page 42 lists the mappings for all 'binary' columns to return as the Java type 'byte[]', and I don't see anywhere in the JDBC-2 or JDBC-3 specs that overrides this...the JDBC-2 spec also explicitly states that you need to use getBlob() to get a java.sql.Blob instance from a result set on page 31). Changing this behavior would most likely many applications. Is there a reason you can't call getBlob() directly?

An aside to this issue is that the getObject method seems to try and de-serialize a java object from a blob. I'm not sure that follows from the stated documentation of getObject(int column).

This is a convenience feature, because MySQL doesn't have a native 'java object' type, but many people do store serialized java objects in MySQL. There is no performance cost for this (checking two bytes for the 'serialization' magic header). If this is causing issues for people, we can certainly have this be an option that can be configured to be turned on/off by a property.

Regards,

-Mark - -- Mr. Mark Matthews MySQL AB, Software Development Manager, J2EE and Windows Platforms Office: +1 708 557 2388 www.mysql.com

Are you MySQL Certified? http://www.mysql.com/certification/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.3 (MingW32) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQE/gtOytvXNTca6JD8RAsMmAJ0VsAQAF0GXpG5/uxlNTvjWPBcLFACfVVjF TpmX+Kl3mAu4FBMFkGiP0Do= =0+Q7 -----END PGP SIGNATURE-----