MySQL和Java数据类型之间的可能转换
These MySQL Data TypesCan always be converted to these Java types
CHAR, VARCHAR, BLOB, TEXT, ENUM, and SETjava.lang.String, java.io.InputStream, java.io.Reader, java.sql.Blob, java.sql.Clob
FLOAT, REAL, DOUBLE PRECISION, NUMERIC, DECIMAL, TINYINT, SMALLINT, MEDIUMINT, INTEGER, BIGINTjava.lang.String, java.lang.Short, java.lang.Integer, java.lang.Long, java.lang.Double, java.math.BigDecimal
DATE, TIME, DATETIME, TIMESTAMPjava.lang.String, java.sql.Date, java.sql.Timestamp

ResultSet.getObject()方法使用MySQL和Java类型之间的类型转换,并在适当时遵循JDBC规范。ResultSetMetaData.GetColumnTypeName()和 返回的值 ResultSetMetaData.GetColumnClassName() 如下表所示.有关JDBC类型的更多信息,请参见 java.sql.Types类上的参考 。

ResultSetMetaData.GetColumnTypeName() 和 ResultSetMetaData.GetColumnClassName() 的MySQL类型和返回值
MySQL Type NameReturn value of GetColumnTypeNameReturn value of GetColumnClassName
BIT(1)BITjava.lang.Boolean
BIT( > 1)BITbyte[]
TINYINTTINYINTjava.lang.Boolean if the configuration property tinyInt1isBit is set to true (the default) and the storage size is 1, or java.lang.Integer if not.
BOOL, BOOLEANTINYINTSee TINYINT, above as these are aliases for TINYINT(1), currently.
SMALLINT[(M)] [UNSIGNED]SMALLINT [UNSIGNED]java.lang.Integer (regardless of whether it is UNSIGNED or not)
MEDIUMINT[(M)] [UNSIGNED]MEDIUMINT [UNSIGNED]java.lang.Integer (regardless of whether it is UNSIGNED or not)
INT,INTEGER[(M)] [UNSIGNED]INTEGER [UNSIGNED]java.lang.Integer, if UNSIGNED java.lang.Long
BIGINT[(M)] [UNSIGNED]BIGINT [UNSIGNED]java.lang.Long, if UNSIGNED java.math.BigInteger
FLOAT[(M,D)]FLOATjava.lang.Float
DOUBLE[(M,B)]DOUBLEjava.lang.Double
DECIMAL[(M[,D])]DECIMALjava.math.BigDecimal
DATEDATEjava.sql.Date
DATETIMEDATETIMEjava.sql.Timestamp
TIMESTAMP[(M)]TIMESTAMPjava.sql.Timestamp
TIMETIMEjava.sql.Time
`YEAR[(24)]`YEAR
CHAR(M)CHARjava.lang.String (unless the character set for the column is BINARY, then byte[] is returned.
VARCHAR(M) [BINARY]VARCHARjava.lang.String (unless the character set for the column is BINARY, then byte[] is returned.
BINARY(M)BINARYbyte[]
VARBINARY(M)VARBINARYbyte[]
TINYBLOBTINYBLOBbyte[]
TINYTEXTVARCHARjava.lang.String
BLOBBLOBbyte[]
TEXTVARCHARjava.lang.String
MEDIUMBLOBMEDIUMBLOBbyte[]
MEDIUMTEXTVARCHARjava.lang.String
LONGBLOBLONGBLOBbyte[]
LONGTEXTVARCHARjava.lang.String
ENUM('value1','value2',...)CHARjava.lang.String
SET('value1','value2',...)CHARjava.lang.String

java.sql.Types

Modifier and TypeField and Description
static intARRAYThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type ARRAY.
static intBIGINTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIGINT.
static intBINARYThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BINARY.
static intBITThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIT.
static intBLOBThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BLOB.
static intBOOLEANThe constant in the Java programming language, somtimes referred to as a type code, that identifies the generic SQL type BOOLEAN.
static intCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type CHAR.
static intCLOBThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type CLOB.
static intDATALINKThe constant in the Java programming language, somtimes referred to as a type code, that identifies the generic SQL type DATALINK.
static intDATEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DATE.
static intDECIMALThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DECIMAL.
static intDISTINCTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DISTINCT.
static intDOUBLEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DOUBLE.
static intFLOATThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type FLOAT.
static intINTEGERThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type INTEGER.
static intJAVA_OBJECTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type JAVA_OBJECT.
static intLONGNVARCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGNVARCHAR.
static intLONGVARBINARYThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGVARBINARY.
static intLONGVARCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGVARCHAR.
static intNCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NCHAR
static intNCLOBThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NCLOB.
static intNULLThe constant in the Java programming language that identifies the generic SQL value NULL.
static intNUMERICThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NUMERIC.
static intNVARCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NVARCHAR.
static intOTHERThe constant in the Java programming language that indicates that the SQL type is database-specific and gets mapped to a Java object that can be accessed via the methods getObject and setObject.
static intREALThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REAL.
static intREFThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REF.
static intREF_CURSORThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REF CURSOR.
static intROWIDThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type ROWID
static intSMALLINTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type SMALLINT.
static intSQLXMLThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type XML.
static intSTRUCTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type STRUCT.
static intTIMEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIME.
static intTIME_WITH_TIMEZONEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIME WITH TIMEZONE.
static intTIMESTAMPThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP.
static intTIMESTAMP_WITH_TIMEZONEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP WITH TIMEZONE.
static intTINYINTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TINYINT.
static intVARBINARYThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type VARBINARY.
static intVARCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type VARCHAR.