您的位置:首页 > 编程语言 > Java开发

Java数据类型和MySql数据类型对应表

2016-08-11 11:13 387 查看
java mysql 数据类型对照

Table 20.25. MySQL Types to Java Types for ResultSet.getObject()
MySQL Type NameReturn value ofGetColumnClassNameReturned as Java Class
BIT(1) (new in MySQL-5.0)BITjava.lang.Boolean
BIT( > 1) (new in MySQL-5.0)BITbyte[]
TINYINTTINYINTjava.lang.Boolean if the configuration property tinyInt1isBit is set to true (the default) and the storage size is 1, orjava.lang.Integer if not.
BOOL, BOOLEANTINYINTSee TINYINT, above as these are aliases forTINYINT(1), currently.
SMALLINT[(M)] [UNSIGNED]SMALLINT [UNSIGNED]java.lang.Integer (regardless ifUNSIGNED or not)
MEDIUMINT[(M)] [UNSIGNED]MEDIUMINT [UNSIGNED]java.lang.Integer, if UNSIGNEDjava.lang.Long (C/J 3.1 and earlier), orjava.lang.Integer for C/J 5.0 and later
INT,INTEGER[(M)] [UNSIGNED]INTEGER [UNSIGNED]java.lang.Integer, if UNSIGNEDjava.lang.Long
BIGINT[(M)] [UNSIGNED]BIGINT [UNSIGNED]java.lang.Long, if UNSIGNEDjava.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 isjava.sql.Short. If set to true (the default), then the returned object is of typejava.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
对于boolean类型,在MySQL数据库中,个人认为用int类型代替较好,对bit操作不是很方便,尤其是在具有web页面开发的项目中,表示0/1,对应Java类型的Integer较好。

我的概念中,mysql中的text字段应该是没有长度限制的,但是今天事实告诉我,text类型的长度是有限制的。其中mysql的text类型有64K长度限制的

工作中由于邮件的长度超过了64k,Text已经不适用,我们换用了MEDIUMTEXT 他的长度为16777215 (2^24 - 1) 为256*64K=16M
对于bolb,一般用于对图片的数据库存储,原理是把图片打成二进制,然后进行的一种存储方式,在java中对应byte[]数组。

mysql官方文档:

http://dev.mysql.com/doc/refman/5.7/en/data-types.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息