Mybatis:数据库的类型与java类型对应

                               Mybatis与数据库的类型对应


1: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

 

*对于bolb,一般用于对图片的数据库存储,原理是把图片打成二进制,然后进行的一种存储方式,在java中对应byte[]数组。

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

2:SqlServer数据库与MySql数据类型对照表

SQL Server 类型JDBC 类型 (java.sql.Types)Java 语言类型

bigint

BIGINT

long

timestamp

binary

BINARY

byte[]

bit

BIT

boolean

char

CHAR

String

decimal

money

smallmoney

DECIMAL

java.math.BigDecimal

float

DOUBLE

double

int

INTEGER

int

image

varbinary(max)

LONGVARBINARY

byte[]

varchar(max)

text

LONGVARCHAR

String

nchar

CHAR

NCHAR (Java SE 6.0)

String

nvarchar

VARCHAR

NVARCHAR (Java SE 6.0)

String

nvarchar(max)

ntext

LONGVARCHAR

LONGNVARCHAR (Java SE 6.0)

String

numeric

NUMERIC

java.math.BigDecimal

real

REAL

float

smallint

SMALLINT

short

datetime

smalldatetime

TIMESTAMP

java.sql.Timestamp

varbinary

udt

VARBINARY

byte[]

varchar

VARCHAR

String

tinyint

TINYINT

short

uniqueidentifier

CHAR

String

xml

LONGVARCHAR

SQLXML (Java SE 6.0)

String

SQLXML

time

TIME (1)

java.sql.Time (1)

date

DATE

java.sql.Date

datetime2

TIMESTAMP

java.sql.Timestamp

datetimeoffset (2)

microsoft.sql.Types.DATETIMEOFFSET

microsoft.sql.DateTimeOffset

3:sqlserver和Oracle数据类型对应关系

A.SqlServer 2k转换为Oracle 10g

列名SqlServer数据类型SqlServer长度Oracle数据类型
column1bigint8NUMBER(19)
column2binary50RAW(50)
column3bit1NUMBER(2)
column4char10CHAR(10)
column5datetime8DATE
column6decimal9NUMBER(18)
column7float8BINARY_DOUBLE
column8image16BLOB
column9int4NUMBER(10)
column10money8NUMBER(19,4)
column11nchar10NCHAR(10)
column12ntext16NCLOB
column13numeric9NUMBER(18)
column14nvarchar50NVARCHAR2(50)
column15real4BINARY_FLOAT
column16smalldatetime4DATE
column17smallint2NUMBER(5)
column18smallmoney4NUMBER(10,4)
column19sql_variant BLOB
column20text16CLOB
column21timestamp8RAW(8)
column22tinyint1NUMBER(3)
column23uniqueidentifier16BLOB
column24varbinary50RAW(50)
column25varchar50VARCHAR2(50)
 

B.Oracle 10g 转换为SqlServer 2k

Oracle列名Oracle数据类型SqlServer列名SqlServer数据类型SqlServer数据长度
COLUMN1BINARY_DOUBLECOLUMN1float8
COLUMN2BINARY_FLOATCOLUMN2real4
COLUMN3BLOBCOLUMN3image16
COLUMN4CLOBCOLUMN4ntext16
COLUMN5CHAR(10)COLUMN5nchar10
COLUMN6DATECOLUMN6datetime8
COLUMN12NUMBERCOLUMN12numeric13
COLUMN13NVARCHAR2(10)COLUMN13nvarchar10
COLUMN14RAW(10)COLUMN14varbinary10
COLUMN15TIMESP(6)COLUMN15datetime8
COLUMN16TIMESP(6) WITH LOCAL TIME ZONECOLUMN16datetime8
COLUMN17TIMESP(6) WITH TIME ZONECOLUMN17datetime8
COLUMN18VARCHAR2(10)COLUMN18nvarchar10
COLUMN7INTERVAL DAY(2) TO SECOND(6)COLUMN7nvarchar30
COLUMN8INTERVAL YEAR(2) TO MONTHCOLUMN8nvarchar14
COLUMN9LONGCOLUMN9ntext16
COLUMN10LONG RAWCOLUMN10image16
COLUMN11NCLOBCOLUMN11ntext16
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页