Java和MySQL数据类型对应一览

来源:互联网 发布:js防止表单二次提交 编辑:程序博客网 时间:2024/04/28 13:27

Java和MySQL数据类型对应一览



Table 20.25. MySQL Types to Java Types for ResultSet.getObject()MySQL Type NameReturn value ofGetColumnClassNameReturned as Java ClassBIT(1) (new in MySQL-5.0)BITjava.lang.BooleanBIT( > 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 laterINT,INTEGER[(M)] [UNSIGNED]INTEGER [UNSIGNED]java.lang.Integer, if UNSIGNEDjava.lang.LongBIGINT[(M)] [UNSIGNED]BIGINT [UNSIGNED]java.lang.Long, if UNSIGNEDjava.math.BigIntegerFLOAT[(M,D)]FLOATjava.lang.FloatDOUBLE[(M,B)]DOUBLEjava.lang.DoubleDECIMAL[(M[,D])]DECIMALjava.math.BigDecimalDATEDATEjava.sql.DateDATETIMEDATETIMEjava.sql.TimestampTIMESTAMP[(M)]TIMESTAMPjava.sql.TimestampTIMETIMEjava.sql.TimeYEAR[(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.StringBLOBBLOBbyte[]TEXTVARCHARjava.lang.StringMEDIUMBLOBMEDIUMBLOBbyte[]MEDIUMTEXTVARCHARjava.lang.StringLONGBLOBLONGBLOBbyte[]LONGTEXTVARCHARjava.lang.StringENUM('value1','value2',...)CHARjava.lang.StringSET('value1','value2',...)CHARjava.lang.String

对于boolean类型,在mysql数据库中,个人认为用int类型代替较好,对bit操作不是很方便,尤其是在具有web页面开发的项目中,表示0/1,对应java类型的Integer较好。

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

工作中由于邮件的长度超过了64k,Text已经不适用,我们换用了MEDIUMTEXT 他的长度为16777215 (2^24 - 1) 为256*64K=16M

0 0
原创粉丝点击