MySQL基本数据类型与Java基本数据类型


           早上写了篇博客,发现蛮有感觉的,工作了一整天,发现又有些东西可以写了,呵呵……  分享下……  微笑


           经过几天的Dao层和Service层代码的编写,今天终于到了看成果的时候了,把项目启动后,输入一个Url访问项目接口。糟糕,报错,没事,Dao层的错误,没问题,就是SQL的问题。说明下,我们公司操作数据库是用jdbc的,所有比较麻烦,但是效率相对来说是蛮高的。

          但是,我仔细对比了代码,没发现问题了,但总是抱 “Statement parameter 13 not set.” 错误。

         没办法,只能一步一步的找咯。我把Sql语句和各个参数都打印出来。然后放到SQLyog里去执行。没问题额。惊讶

        我把tomcat在次启动,访问接口,还是抱 “Statement parameter 13 not set.” 错误。我在仔细看了下,不会是关键字的问题了吧?唉……  试下呗,Pass 。哦,我焕然大雾,原来是类型不匹配,Java是short类型,mysql是tinyint类型。

       下面是我从网上找来的Java基本数据类型和mysql基本数据类型对照表:

BIT(1) (new in MySQL-5.0) BIT java.lang.Boolean
BIT( > 1) (new in MySQL-5.0) BIT byte[]
TINYINT TINYINT java.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, BOOLEAN TINYINT See 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), or java.lang.Integer for C/J 5.0 and later
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)] FLOAT java.lang.Float
DOUBLE[(M,B)] DOUBLE java.lang.Double
DECIMAL[(M[,D])] DECIMAL java.math.BigDecimal
DATE DATE java.sql.Date
DATETIME DATETIME java.sql.Timestamp
TIMESTAMP[(M)] TIMESTAMP java.sql.Timestamp
TIME TIME java.sql.Time
YEAR[(2|4)] YEAR If 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) CHAR java.lang.String (unless the character set for the column is BINARY, then byte[] is returned.
VARCHAR(M) [BINARY] VARCHAR java.lang.String (unless the character set for the column is BINARY, then byte[] is returned.
BINARY(M) BINARY byte[]
VARBINARY(M) VARBINARY byte[]
TINYBLOB TINYBLOB byte[]
TINYTEXT VARCHAR java.lang.String
BLOB BLOB byte[]
TEXT VARCHAR java.lang.String
MEDIUMBLOB MEDIUMBLOB byte[]
MEDIUMTEXT VARCHAR java.lang.String
LONGBLOB LONGBLOB byte[]
LONGTEXT VARCHAR java.lang.String
ENUM('value1','value2',...) CHAR java.lang.String
SET('value1','value2',...) CHAR java.lang.String

posted @ 2012-02-21 22:17  li.zhiliang  阅读(214)  评论(0编辑  收藏  举报