java数据类型和mySql数据类型对应一览
类型名称显示长度数据库类型JAVA类型JDBC类型索引(int)描述??????VARCHARL+NVARCHARjava.lang.String12?CHARNCHARjava.lang.String1?BLOBL+NBLOBjava.lang.byte[]-4?TEXT65535VARCHARjava.lang.String-1???????INTEGER4INTEGER UNSIGNEDjava.lang.Long4?TINYINT3TINYINT UNSIGNEDjava.lang.Integer-6?SMALLINT5SMALLINT UNSIGNEDjava.lang.Integer5?MEDIUMINT8MEDIUMINT UNSIGNEDjava.lang.Integer4?BIT1BITjava.lang.Boolean-7?BIGINT20BIGINT UNSIGNEDjava.math.BigInteger-5?FLOAT4+8FLOATjava.lang.Float7?DOUBLE22DOUBLEjava.lang.Double8?DECIMAL11DECIMALjava.math.BigDecimal3?BOOLEAN1同TINYINT?????????ID11PK (INTEGER UNSIGNED)java.lang.Long4???????DATE10DATEjava.sql.Date91?TIME8TIMEjava.sql.Time92?DATETIME19DATETIMEjava.sql.Timestamp93?TIMESTAMP19TIMESTAMPjava.sql.Timestamp93?YEAR4YEARjava.sql.Date91
以上就是Java数据类型和MySql数据类型对应表。
对于bolb,一般用于对图片的数据库存储,原理是把图片打成二进制,然后进行的一种存储方式,在java中对应byte[]数组。
对于boolen类型,在mysql数据库中,个人认为用int类型代替较好,对bit操作不是很方便,尤其是在具有web页面开发的项目中,表示0/1,对应java类型的Integer较好。
java.lang.Boolean
BIT( > 1)?(new in MySQL-5.0)BITbyte[]
TINYINTTINYINTjava.lang.Boolean
?if the configuration property?tinyInt1isBit
?is set totrue
?(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 if UNSIGNED or not)MEDIUMINT[(M)] [UNSIGNED]MEDIUMINT [UNSIGNED]java.lang.Integer,
?if UNSIGNED?java.lang.Long
?(C/J 3.1 and earlier), orjava.lang.Integer
?for C/J 5.0 and laterINT,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[(2|4)]YEARIf?yearIsDateType
?configuration property is set to false, then the returned object type is?java.sql.Short
. If set to true (the default) then an object of type?java.sql.Date
?(with the date set to January 1st, at midnight).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
mysql官方文档:
http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-type-conversions.html