MySQL Connector/J is flexible in the way it handles conversions between MySQL data types and Java data types.
In general, any MySQL data type can be converted to a
java.lang.String, and any numeric type can be
converted to any of the Java numeric types, although round-off,
overflow, or loss of precision may occur.
TEXT types return
Types.LONGVARCHAR with different
getPrecision() values (65535, 255,
16777215, and 2147483647 respectively) with
-1. This behavior is intentional even
TINYTEXT does not fall, regarding to
its size, within the
This is to avoid different handling inside the same base type.
-1 because the internal server handling is
TEXT, which is similar to
Also note that
VARCHAR even though
VARCHAR is the designated column
database-specific name for this type.
Starting with Connector/J 3.1.0, the JDBC driver issues warnings
DataTruncation exceptions as is
required by the JDBC specification unless the connection was
configured not to do so by using the property
jdbcCompliantTruncation and setting it to
The conversions that are always guaranteed to work are listed in the following table. The first column lists one or more MySQL data types, and the second column lists one or more Java types to which the MySQL types can be converted.
Table 21.24. Connection Properties - Miscellaneous
|These MySQL Data Types||Can always be converted to these Java types|
Round-off, overflow or loss of precision may occur if you choose a Java numeric data type that has less precision or capacity than the MySQL data type you are converting to/from.
ResultSet.getObject() method uses the
type conversions between MySQL and Java types, following the
JDBC specification where appropriate. The value returned by
also shown below. For more information on the
java.sql.Types classes see
2 Platform Types.
Table 21.25. MySQL Types to Java Types for ResultSet.getObject()
|MySQL Type Name||Return value of ||Returned as Java Class|