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 | ARRAYThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type ARRAY. |
static int | BIGINTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIGINT. |
static int | BINARYThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BINARY. |
static int | BITThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BIT. |
static int | BLOBThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type BLOB. |
static int | BOOLEANThe constant in the Java programming language, somtimes referred to as a type code, that identifies the generic SQL type BOOLEAN. |
static int | CHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type CHAR. |
static int | CLOBThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type CLOB. |
static int | DATALINKThe constant in the Java programming language, somtimes referred to as a type code, that identifies the generic SQL type DATALINK. |
static int | DATEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DATE. |
static int | DECIMALThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DECIMAL. |
static int | DISTINCTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DISTINCT. |
static int | DOUBLEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type DOUBLE. |
static int | FLOATThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type FLOAT. |
static int | INTEGERThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type INTEGER. |
static int | JAVA_OBJECTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type JAVA_OBJECT. |
static int | LONGNVARCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGNVARCHAR. |
static int | LONGVARBINARYThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGVARBINARY. |
static int | LONGVARCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type LONGVARCHAR. |
static int | NCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NCHAR |
static int | NCLOBThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NCLOB. |
static int | NULLThe constant in the Java programming language that identifies the generic SQL value NULL. |
static int | NUMERICThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NUMERIC. |
static int | NVARCHARThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type NVARCHAR. |
static int | OTHERThe 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 | REALThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REAL. |
static int | REFThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REF. |
static int | REF_CURSORThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type REF CURSOR. |
static int | ROWIDThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type ROWID |
static int | SMALLINTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type SMALLINT. |
static int | SQLXMLThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type XML. |
static int | STRUCTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type STRUCT. |
static int | TIMEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIME. |
static int | TIME_WITH_TIMEZONEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIME WITH TIMEZONE. |
static int | TIMESTAMPThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP. |
static int | TIMESTAMP_WITH_TIMEZONEThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TIMESTAMP WITH TIMEZONE. |
static int | TINYINTThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type TINYINT. |
static int | VARBINARYThe constant in the Java programming language, sometimes referred to as a type code, that identifies the generic SQL type VARBINARY. |
static int | VARCHARThe 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
评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果



