Home  >  Article  >  Database  >  Comparison table between Java data types and MySql data types_MySQL

Comparison table between Java data types and MySql data types_MySQL

WBOY
WBOYOriginal
2016-07-06 13:32:461414browse

This article describes the comparison table between Java data types and MySql data types. Share it with everyone for your reference, the details are as follows:


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 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





For bolb, it is generally used for database storage of images. The principle is to convert the image into binary and then perform a storage method, which corresponds to the byte[] array in Java.

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

Readers who are interested in more MySQL-related content can check out the special topics on this site: "A Complete Collection of MySQL Log Operation Skills", "A Summary of MySQL Transaction Operation Skills", "A Complete Collection of MySQL Stored Procedure Skills", and "A Summary of MySQL Database Lock Related Skills" 》and《Summary of commonly used functions in MySQL》

I hope this article will be helpful to everyone in MySQL database planning.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn