The type of Mybatis database corresponds to the java type

Mybatis corresponds to the type of database


1: Java data type and MySql data type comparison table

type name Display length Database type JAVA type JDBC type index (int)
VARCHAR L+N VARCHAR java.lang.String 12
CHAR N CHAR java.lang.String 1
BLOB L+N BLOB java.lang.byte [] -4
TEXT 65535 VARCHAR java.lang.String -1
INTEGER 4 INTEGER UNSIGNED java.lang.Long 4
TINYINT 3 TINYINT UNSIGNED java.lang.Integer -6
SMALLINT 5 SMALLINT UNSIGNED java.lang.Integer 5
MEDIUMINT 8 MEDIUMINT UNSIGNED java.lang.Integer 4
BIT 1 BIT java.lang.Boolean -7
BIGINT 20 BIGINT UNSIGNED java.math.BigInteger -5
FLOAT 4+8 FLOAT java.lang.Float 7
DOUBLE 22 DOUBLE java.lang.Double 8
DECIMAL 11 DECIMAL java.math.BigDecimal 3
BOOLEAN 1 同TINYINT    
ID 11 PK (INTEGER UNSIGNED) java.lang.Long 4
DATE 10 DATE java.sql.Date 91
TIME 8 TIME java.sql.Time 92
DATETIME 19 DATETIME java.sql.Timestamp 93
TIMESTAMP 19 TIMESTAMP java.sql.Timestamp 93
YEAR 4 YEAR java.sql.Date 91

 

*For bolb, it is generally used for database storage of pictures. The principle is to type pictures into binary and then perform a storage method, corresponding to byte[] array in java.

For the boolen type, in the mysql database, I personally think that it is better to replace the int type, which is not very convenient for bit operations, especially in projects with web page development, it means 0/1, and the java type Integer is better.

2: SqlServer database and MySql data type comparison table

SQL Server type JDBC types (java.sql.Types) Java language type

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数据类型
column1 bigint 8 NUMBER(19)
column2 binary 50 RAW(50)
column3 bit 1 NUMBER(2)
column4 char 10 CHAR(10)
column5 datetime 8 DATE
column6 decimal 9 NUMBER(18)
column7 float 8 BINARY_DOUBLE
column8 image 16 BLOB
column9 int 4 NUMBER(10)
column10 money 8 NUMBER(19,4)
column11 nchar 10 NCHAR(10)
column12 ntext 16 NCLOB
column13 numeric 9 NUMBER(18)
column14 nvarchar 50 NVARCHAR2(50)
column15 real 4 BINARY_FLOAT
column16 smalldatetime 4 DATE
column17 smallint 2 NUMBER(5)
column18 smallmoney 4 NUMBER(10,4)
column19 sql_variant   BLOB
column20 text 16 CLOB
column21 timestamp 8 RAW(8)
column22 tinyint 1 NUMBER(3)
column23 uniqueidentifier 16 BLOB
column24 varbinary 50 RAW(50)
column25 varchar 50 VARCHAR2(50)
 

B.Oracle 10g 转换为SqlServer 2k

Oracle列名 Oracle数据类型 SqlServer列名 SqlServer数据类型 SqlServer数据长度
COLUMN1 BINARY_DOUBLE COLUMN1 float 8
COLUMN2 BINARY_FLOAT COLUMN2 real 4
COLUMN3 BLOB COLUMN3 image 16
COLUMN4 CLOB COLUMN4 ntext 16
COLUMN5 CHAR(10) COLUMN5 nchar 10
COLUMN6 DATE COLUMN6 datetime 8
COLUMN12 NUMBER COLUMN12 numeric 13
COLUMN13 NVARCHAR2(10) COLUMN13 nvarchar 10
COLUMN14 RAW(10) COLUMN14 varbinary 10
COLUMN15 TIMESP(6) COLUMN15 datetime 8
COLUMN16 TIMESP(6) WITH LOCAL TIME ZONE COLUMN16 datetime 8
COLUMN17 TIMESP(6) WITH TIME ZONE COLUMN17 datetime 8
COLUMN18 VARCHAR2(10) COLUMN18 nvarchar 10
COLUMN7 INTERVAL DAY(2) TO SECOND(6) COLUMN7 nvarchar 30
COLUMN8 INTERVAL YEAR(2) TO MONTH COLUMN8 nvarchar 14
COLUMN9 LONG COLUMN9 ntext 16
COLUMN10 LONG RAW COLUMN10 image 16
COLUMN11 NCLOB COLUMN11 ntext 16

Guess you like

Origin blog.csdn.net/zhouzhiwengang/article/details/112506530