관리 메뉴

한글창제의 기쁨

JAVA Mysql 타입 매칭 본문

DataBase/mysql

JAVA Mysql 타입 매칭

timesurfer 공간지배자 2018.08.06 11:36

25.4.4.2. 자바, JDBC 그리고 MySQL 타입

 

MySQL Connector/J MySQL 데이터 타입과 자바 데이터 타입 간의 변환을 유연하게 처리한다.

일반적으로모든 MySQL 데이터 타입은 java.lang.String으로 변환할  있고모든 수식 타입도자바 수식 타입으로 변환할  있다.

다음과 같은 타입 변환은 항상 보장된다:

 

Connection Properties - Miscellaneous. 

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() 방식은 JDBC 지정하는 방식으로 MySQL 자바 타입 간의 타입변환을   사용한다ResultSetMetaData.GetColumnClassName() 리턴하는 값이 아래와나와 있다.

MySQL Types to Java Types for ResultSet.getObject(). 

 

MySQL Type Name

Return value of GetColumnClassName

Returned as Java Class

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 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 if UNSIGNED or not)

MEDIUMINT[(M)] [UNSIGNED]

MEDIUMINT [UNSIGNED]

java.lang.Integer, if UNSIGNED java.lang.Long

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

If yearIsDateTypeconfiguration Property is set to false, then the returned object type is java.sql.Short. If set to true (the default) then an object of type java.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, 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



출처 : http://www.mysqlkorea.com/sub.html?mcode=manual&scode=01_1&m_no=23841&cat1=1434&cat2=1438&cat3=1458&lang=k


'DataBase > mysql' 카테고리의 다른 글

mysql 사용자 추가 DB 권한부여  (0) 2018.09.18
JAVA Mysql 타입 매칭  (0) 2018.08.06
0 Comments
댓글쓰기 폼