Comments - ResultSetMetaData getColumnClassName accuracy for JDBC

8 years ago Vladislav Vaintroub

Can you describe what is the error , and what do you expect instead.

If "[B" makes you wonder, this is the java class name for byte array . This is for example what System.out.println((new byte[1]).getClass().getName()); would print.

TINYINT(1) is boolean, as MySQL does not have a bona fide boolean

VARCHAR is string, unless its encoding is binary, in which case it is byte array

8 years ago Tommy Pham


Consider this sample DB table [1], I was hoping to extract with the Java code:

Object o = Class.forName(rsmd.getColumnClassName(0)).newInstance();

For most column types (varchar, int, boolean, etc...), I don't see it as a problem. For binary, blob, etc, it's a problem. Please see ResultSetMetaData log dump [2] of each column in the sample table [1].

Regards, Tommy



8 years ago Vladislav Vaintroub

I'm not sure that your use case is aligned with JDBC understanding of what this method should return. There is a test case that checks, among other things that

resutSet.getObject(index).getClass().getName() is the same as resultSetMetaData.getColumnClassName(index)

See here

That in my understanding, was what JDBC required. Why would you need to instantiate Objects with newInstance at all, what are you trying to achieve

8 years ago Tommy Pham

I'm testing one of my theories. I'll just make adaptation similar to the getClassName [1] and use getColumnType as that seems to be more reliable and the returned type seems to be one of the java.sql.Types.

Thanks, Tommy


8 years ago Tommy Pham

For the BLOB MariaDB datatype, I was expecting the getColumnClassName to be "java.sql.Blob".

8 years ago Tommy Pham

or javax.sql.rowset.serial.SerialBlob since java.sql.Blob is just an interface.

8 years ago Vladislav Vaintroub

Well, the getObject() method for blob fields returns byte array, not javax.sql.rowset.serial.SerialBlob , thus the method returns "[B"

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.