Data type Mapping

In this chapter you will learn:

  1. Map Java data type to database data type

Data type mapping and corresponding methods

JDBC driver converts the Java data type to database back and forth. The following table summarizes the JDBC vs Java data type mapping.

The mapping is used by PreparedStatement, CallableStatement and ResultSet.

Database Java Method
VARCHAR java.lang.String getString / setString / updateString
CHARjava.lang.String getString / setString / updateString
LONGVARCHAR java.lang.String getString / setString / updateString
BIT boolean getBoolean / setBoolean / updateBoolean
NUMERIC java.math.BigDecimal getBigDecimal / setBigDecimal / updateBigDecimal
TINYINT byte getByte / setByte / updateByte
SMALLINT short getShort / setShort / updateShort
INTEGER int getInt / setInt / updateInt
BIGINT long getLong / setLong / updateLong
REAL float getFloat / setFloat / updateFloat
FLOAT float getFloat / setFloat / updateFloat
DOUBLE double getDouble / setDouble / updateDouble
VARBINARY byte[ ] getBytes / setBytes / updateBytes
BINARY byte[ ] getBytes / setBytes / updateBytes
DATE java.sql.Date getDate / setDate / updateDate
TIME java.sql.Time getTime / setTime / updateTime
TIMESTAMP java.sql.Timestamp getTimestamp / setTimestamp / updateTimestamp
CLOB java.sql.Clob getClob / setClob / updateClob
BLOB java.sql.Blob getBlob / setBlob / updateBlob
ARRAY java.sql.Array getARRAY / setARRAY / updateARRAY
REF java.sql.Ref getRef / setRef / updateRef
STRUCT java.sql.Struct getStruct / setStruct / updateStruct

Next chapter...

What you will learn in the next chapter:

  1. How to insert blob type data to database
Home » Java Tutorial » SQL Data Types

Data Type

    Data type Mapping
    Blob type data insert
    Blob type data read
    Clob type data insert with FileInputStream
    Clob data insert with FileReader
    Clob data read
    Image file insert
    Image file retrieve
    Byte array insert and retrieve
    Date value insert
    Date value retrieve
    Date value for a Time Zone
    TIME value insert
    TIME value retrieve
    TIMESTAMP value
    TIMESTAMP type value retrieve
    Decimal insert

NULL

    NULL Values
    NULL primitive data types

SQL Date, TimeStamp, Time

    JDBC Date time types
    Create sql Date from string for certain format
    SQL Date from Calendar
    Create sql Date from String
    TimeStamp from milli-second
    Create TimeStamp from String
    Create TimeStamp from year, month and day, hour, minute and second
    TimeStamp Now
    Format TimeStamp
    TimeStamp to readable string
    Convert TimeStamp to Date
    Create TimeStamp from String with format
    Convert Date to Time
    Convert TIME to Calendar