MySQL8与Java类型对照表
MySQL和Java数据类型之间的可能转换
These MySQL Data Types | Can always be converted to these Java types |
---|---|
CHAR, VARCHAR, BLOB, TEXT, ENUM, and SET | java.lang.String, java.io.InputStream, java.io.Reader, java.sql.Blob, java.sql.Clob |
FLOAT, REAL, DOUBLE PRECISION, NUMERIC, DECIMAL, TINYINT, SMALLINT, MEDIUMINT, INTEGER, BIGINT | java.lang.String, java.lang.Short, java.lang.Integer, java.lang.Long, java.lang.Double, java.math.BigDecimal |
DATE, TIME, DATETIME, TIMESTAMP | java.lang.String, java.sql.Date, java.sql.Timestamp |
ResultSet.getObject()方法使用MySQL和Java类型之间的类型转换,并在适当时遵循JDBC规范。ResultSetMetaData.GetColumnTypeName()和 返回的值 ResultSetMetaData.GetColumnClassName() 如下表所示.有关JDBC类型的更多信息,请参见 java.sql.Types类上的参考 。
ResultSetMetaData.GetColumnTypeName() 和 ResultSetMetaData.GetColumnClassName() 的MySQL类型和返回值
MySQL Type Name | Return value of GetColumnTypeName | Return value of GetColumnClassName |
---|---|---|
BIT(1) | BIT | java.lang.Boolean |
BIT( > 1) | BIT | byte[] |
TINYINT | TINYINT | java.lang.Boolean if the configuration property tinyInt1isBit is set to true (the default) and the storage size is 1, or java.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 of whether it is UNSIGNED or not) |
MEDIUMINT[(M)] [UNSIGNED] | MEDIUMINT [UNSIGNED] | java.lang.Integer (regardless of whether it is UNSIGNED or not) |
INT,INTEGER[(M)] [UNSIGNED] | INTEGER [UNSIGNED] | java.lang.Integer , if UNSIGNED java.lang.Long |
BIGINT[(M)] [UNSIGNED] | BIGINT [UNSIGNED] | java.lang.Long , if UNSIGNED java.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 |
CHAR(M) | CHAR | java.lang.String (unless the character set for the column is BINARY , then byte[] is returned. |
VARCHAR(M) [BINARY] | VARCHAR | java.lang.String (unless the character set for the column is BINARY , then byte[] 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 |
java.sql.Types
Modifier and Type | Field and Description |
---|---|
static int | ARRAY The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type ARRAY . |
static int | BIGINT The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIGINT . |
static int | BINARY The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BINARY . |
static int | BIT The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIT . |
static int | BLOB The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BLOB . |
static int | BOOLEAN The constant in the Java programming language, somtimes referred to as a type code, that identifies the generic SQL type BOOLEAN . |
static int | CHAR The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type CHAR . |
static int | CLOB The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type CLOB . |
static int | DATALINK The constant in the Java programming language, somtimes referred to as a type code, that identifies the generic SQL type DATALINK . |
static int | DATE The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DATE . |
static int | DECIMAL The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DECIMAL . |
static int | DISTINCT The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DISTINCT . |
static int | DOUBLE The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DOUBLE . |
static int | FLOAT The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type FLOAT . |
static int | INTEGER The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type INTEGER . |
static int | JAVA_OBJECT The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type JAVA_OBJECT . |
static int | LONGNVARCHAR The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGNVARCHAR . |
static int | LONGVARBINARY The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGVARBINARY . |
static int | LONGVARCHAR The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGVARCHAR . |
static int | NCHAR The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NCHAR |
static int | NCLOB The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NCLOB . |
static int | NULL The constant in the Java programming language that identifies the generic SQL value NULL . |
static int | NUMERIC The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NUMERIC . |
static int | NVARCHAR The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NVARCHAR . |
static int | OTHER The constant in the Java programming language that indicates that the SQL type is database-specific and gets mapped to a Java object that can be accessed via the methods getObject and setObject . |
static int | REAL The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REAL . |
static int | REF The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REF . |
static int | REF_CURSOR The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REF CURSOR . |
static int | ROWID The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type ROWID |
static int | SMALLINT The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type SMALLINT . |
static int | SQLXML The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type XML . |
static int | STRUCT The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type STRUCT . |
static int | TIME The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIME . |
static int | TIME_WITH_TIMEZONE The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIME WITH TIMEZONE . |
static int | TIMESTAMP The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP . |
static int | TIMESTAMP_WITH_TIMEZONE The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP WITH TIMEZONE . |
static int | TINYINT The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TINYINT . |
static int | VARBINARY The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type VARBINARY . |
static int | VARCHAR The constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type VARCHAR . |
- 感谢你赐予我前进的力量
赞赏者名单
因为你们的支持让我意识到写文章的价值🙏
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 Salted Fish
评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果