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.
for the Boolen type, in the MySQL database, the individual think that using the int type is better, the bit operation is not very convenient, especially in the project with Web page development, represents 0/1, corresponding to the Java type of integer is better. the declaration syntax for the decimal column is decimal (m,d). In mysql5.1, the value range of the parameter:
1, M is the maximum number (precision) of the number. The range is 1~65 (in the older MySQL version, the allowable range is 1~254).
2, D is the number of digits to the right of the decimal point (scale). Its scope is 0~30, but must not exceed M.
Description: Float accounted for 4 bytes, double was 8 bytes, decimail (m,d) accounted for m+2 bytes.
The maximum value for decimal (5, 2) is 9 9 9 9. 9 9, because there are 7 bytes available.
Java data type and MySQL data type correspondence table