In the MYSQL database, what are the common data types? How do they correspond to the data types in java

 

A. Conventional mapping

 

integer or int

int or java.lang.Integer

INTEGER

4 bytes

long

long Long

BIGINT

8 bytes

short

short Short

SMALLINT

2 bytes

byte

byte Byte

TINYINT

1 byte

float

float Float

FLOAT

4 bytes

double

double Double

DOUBLE

8 bytes

big_decimal

java.math.BigDecimal

NUMERIC

NUMERIC(8,2)8 位

character

char Character String

CHAR(1)

fixed-length characters

string

String

VARCHAR

variable length string

boolean

boolean Boolean

BIT

boolean type

yes_no

boolean Boolean

CHAR(1) (YN)

boolean type

true_false

boolean Boolean

CHAR(1) (T-F)

boolean type

 

B. Java time and date types

 

map type

Java type

Standard SQL Types

describe

date

util.Date or sql.Date

DATE

YYYY-MM-DD

time

Date Time

TIME

HH:MM:SS

timestamp

Date Timestamp

TIMESTAMP

YYYYMMDDHHMMSS

calendar

calendar

TIMESTAMP

YYYYMMDDHHMMSS

calendar_date

calendar

DATE

YYYY-MM-DD

 

C. Java Large Object Type

 

map type

Java type

Standard SQL Types

MySQL type

binary

byte[]

VARBINARY (or BLOB)

BLOB

text

String

CLOB

TEXT

serializable

Serializable interface arbitrary implementation class

VARBINARY (or BLOB)

BLOB

clob

java.sql.Clob

CLOB

TEXT

blob

java.sql.Blob

BLOB

BLOB

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

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

 
decimal列的声明语法是decimal(m,d)。
参数的取值范围: 
1、M是数字的最大数(精度)。其范围为1~65(在较旧的MySQL版本中,允许的范围是1~254)。 
2、D是小数点右侧数字的数目(标度)。其范围是0~30,但不得超过M。 
说明:float占4个字节,double占8个字节,decimail(M,D)占M+2个字节。 
如DECIMAL(5, 2) 的最大值为9 9 9 9 . 9 9,因为有7 个字节可用。

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324888216&siteId=291194637