很多时候我们用hibernate的时候往往并不是十分关心数据库类型和java类型的对应关心,因为大多数hbm文件是自动生成的,但有些时候诸如:数据库设计、没有生成工具、使用原始JDBC、使用mybatis(ibatIS)等等情况,就会手动的去对应数据库与java的数据类型关心,当然比较简单的数据类型即使配置错了也会很快发现问题,但有些数据类型却并不是十分常见,这就给程序员带来了很多麻烦。
SQL |
IBM DB2 |
Oracle |
Sybase |
Mysql |
Java |
BIGINT |
BIGINT |
NUMBER (38, 0) |
BIGINT |
BIGINT |
java.lang.long |
IMAGE |
CHAR FOR BIT DATA |
RAW |
BINARY |
IMAGE |
byte[] |
BIT |
N/A |
BIT |
BIT |
BIT |
java.lang.Boolean |
BLOB |
BLOB |
BLOB |
BLOB |
BLOB |
byte[] |
CHAR |
CHAR, GRAPHIC |
CHAR |
CHAR |
CHAR |
java.lang.String |
CLOB |
CLOB, DBCLOB |
CLOB |
CLOB |
CLOB |
java.lang.String |
DATE |
DATE |
DATE |
DATE |
DATE |
java.sql.Date |
DECIMAL |
DECIMAL |
NUMBER |
DECIMAL, MONEY, SMALLMONEY |
DECIMAL |
java.math.BigDecimal |
DOUBLE PRECISION |
DOUBLE |
DOUBLE PRECISION |
DOUBLE PRECISION |
DOUBLE PRECISION |
java.lang.Double |
FLOAT |
FLOAT |
FLOAT |
FLOAT |
FLOAT |
java.lang.Double |
INTEGER |
INTEGER |
INTEGER |
INT |
INTEGER |
java.lang.Integer |
JAVA_OBJECT |
JAVA_OBJECT |
JAVA_OBJECT |
JAVA_OBJECT |
JAVA_OBJECT |
java.lang.Object |
IMAGE |
LONG VARCHAR FOR BIT DATA |
LONG RAW |
IMAGE |
IMAGE |
byte[] |
TEXT |
LONG VARCHAR, LONG VARGRAPHIC |
LONG |
TEXT |
TEXT |
java.lang.String |
NUMERIC |
NUMERIC |
NUMBER |
NUMERIC |
NUMERIC |
java.math.BigDecimal |
OTHER |
OTHER |
OTHER |
OTHER |
OTHER |
java.lang.Object |
REAL |
REAL |
REAL |
REAL |
REAL |
java.lang.Float |
SMALLINT |
SMALLINT |
SMALLINT |
SMALLINT |
SMALLINT |
java.lang.Integer |
TIME |
TIME |
DATE |
TIME |
TIME |
java.sql.Time |
DATETIME |
TIMESTAMP |
DATE |
DATETIME, SMALLDATETIME |
DATETIME |
java.sql.Timestamp |
TINYINT |
SMALLINT |
TINYINT |
TINYINT |
TINYINT |
java.lang.Bute |
IMAGE |
VARCHAR FOR BIT DATA |
RAW |
VARBINARY |
IMAGE |
byte[] |
VARCHAR |
VARCHAR, VARGRAPHIC |
VARCHAR |
VARCHAR |
VARCHAR |
java.lang.String |