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.
Connector/J issues warnings or throws
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 4.5 Possible Conversions Between MySQL and Java Data Types
|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 values returned by
are shown in the table below. For more information on the JDBC
types, see the reference on the
Table 4.6 MySQL Types and Return Values for ResultSetMetaData.GetColumnTypeName()and ResultSetMetaData.GetColumnClassName()
|MySQL Type Name||Return value of ||Return value of |