Ing between Java data types and MySql Data Types [go], data types mysql
Type name |
Display Length |
Database Type |
JAVA type |
JDBC index (int) |
Description |
|
|
|
|
|
|
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 |
Same as 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 |
The preceding table corresponds to the Java data type and MySQL data type.
For bolb, it is generally used to store images in a database. The principle is to compress the images into binary data and then store them in a storage method that corresponds to byte [] arrays in java.
For the boolen type, in the mysql database, I personally think it is better to replace the int type, it is not very convenient for bit operations, especially in projects with web page development, it indicates 0/1, the corresponding java type Integer is better.
BIT (1) (new in MySQL-5.0) |
BIT |
java.lang.Boolean |
BIT (> 1) (new in MySQL-5.0) |
BIT |
byte[] |
TINYINT |
TINYINT |
java.lang.Boolean If the configuration propertytinyInt1isBit Is settrue (The default) and the storage size is 1, orjava.lang.Integer If not. |
BOOL, BOOLEAN |
TINYINT |
See TINYINT, above as these are aliases for TINYINT (1), currently. |
SMALLINT [(M)] [UNSIGNED] |
SMALLINT [UNSIGNED] |
java.lang.Integer (Regardless if UNSIGNED or not) |
MEDIUMINT [(M)] [UNSIGNED] |
MEDIUMINT [UNSIGNED] |
java.lang.Integer, If UNSIGNEDjava.lang.Long (C/J 3.1 and earlier), orjava.lang.Integer For C/J 5.0 and later |
INT, INTEGER [(M)] [UNSIGNED] |
INTEGER [UNSIGNED] |
java.lang.Integer , If UNSIGNEDjava.lang.Long |
BIGINT [(M)] [UNSIGNED] |
BIGINT [UNSIGNED] |
java.lang.Long , If UNSIGNEDjava.math.BigInteger |
FLOAT [(M, D)] |
FLOAT |
java.lang.Float |
DOUBLE [(M, B)] |
DOUBLE |
java.lang.Double |
DECIMAL [(M [, D])] |
DECIMAL |
java.math.BigDecimal |
DATE |
DATE |
java.sql.Date |
DATETIME |
DATETIME |
java.sql.Timestamp |
TIMESTAMP [(M)] |
TIMESTAMP |
java.sql.Timestamp |
TIME |
TIME |
java.sql.Time |
YEAR [(2 | 4)] |
YEAR |
IfyearIsDateType Configuration property is set to false, then the returned object type isjava.sql.Short . If set to true (the default) then an object of typejava.sql.Date (With the date set to January 1st, at midnight ). |
CHAR (M) |
CHAR |
java.lang.String (Unless the character set for the column is BINARY, thenbyte[] Is returned. |
VARCHAR (M) [BINARY] |
VARCHAR |
java.lang.String (Unless the character set for the column is BINARY, thenbyte[] Is returned. |
BINARY (M) |
BINARY |
byte[] |
VARBINARY (M) |
VARBINARY |
byte[] |
TINYBLOB |
TINYBLOB |
byte[] |
TINYTEXT |
VARCHAR |
java.lang.String |
BLOB |
BLOB |
byte[] |
TEXT |
VARCHAR |
java.lang.String |
MEDIUMBLOB |
MEDIUMBLOB |
byte[] |
MEDIUMTEXT |
VARCHAR |
java.lang.String |
LONGBLOB |
LONGBLOB |
byte[] |
LONGTEXT |
VARCHAR |
java.lang.String |
ENUM ('value1', 'value2 ',...) |
CHAR |
java.lang.String |
SET ('value1', 'value2 ',...) |
CHAR |
java.lang.String |