Java MySQL data type comparison
Type name |
Display length |
Database type |
Java type |
JDBC Type index (int) |
Describe |
|
|
|
|
|
|
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 |
With 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, generally used for the database storage of pictures, the principle is to make the picture into binary, and then do a storage method, in Java corresponding to the byte[] array. Explanation of the Boolean type
MySQL does not support bool types.
12345 |
create table xs ( id int primary key, bl boolean ) |
This will create a success, but the checklist structure will find MySQL replacing it with tinyint (1).
That is, when a data is set to the bool type, the database is automatically converted to tinyint (1) data type, in fact, this is a disguised bool. The default value is 1, 2, which corresponds to the true and false of bool, respectively.
In the Java corresponding Pojo class, you can use Java.lang.Boolean or Java.lang.Integer depending on the actual situation.
Java MySQL Data type comparison