JDBC Java SQL Mapping              edit Peter Komisar

reference: ' The JDBC Guide', The Sun Site


//supplemental

The paper from which these tables were obtained can be viewed via the following link.
http://www.javasoft.com/products/jdk/1.1/docs/guide/jdbc/getstart/mapping.doc.html#1008141
 

 JDBC Types Mapped to Java Types
 
 JDBC type   Java type 
 CHAR  String 
 VARCHAR   String
 LONGVARCHAR   String
 NUMERIC  java.math.BigDecimal
 DECIMAL  java.math.BigDecimal
 BIT   boolean
 TINYINT   byte
 SMALLINT  short
 INTEGER  int 
 BIGINT  long
 REAL  float
 FLOAT  double
 DOUBLE   double
 BINARY   byte[]
 VARBINARY   byte[]
 LONGVARBINARY  byte[]
 DATE   java.sql.Date
 TIME   java.sql.Time
 TIMESTAMP   java.sql.Timestamp

Java Types Mapped to JDBC Types

This table shows the reverse of the above mapping. It's shorter as there are fewer Java
types and where they map to more than one type both of the SQL types are shown in
the same row. There are two JDBC/SQL types dropped. Java String type doesn't map
to CHAR. java.math.BigDecimal doesn't map to SQL type DECIMAL. The mapping
for String will normally be VARCHAR but will turn into LONGVARCHAR if the given
value exceeds the driver's limit on VARCHAR values. The same is true for byte[] and
VARBINARY and LONGVARBINARY values.
 
 
 Java type   JDBC
 String   VARCHAR or LONGVARCHAR
 java.math.BigDecimal  NUMERIC
 boolean  BIT 
 byte  TINYINT 
 short  SMALLINT
 int  INTEGER
 long  BIGINT
  float  REAL
 double  DOUBLE
 byte[]  VARBINARY or LONGVARBINARY
 java.sql.Date  DATE 
 java.sql.TimeTIME   TIME
 java.sql.Timestamp  TIMESTAMP 

JDBC Types Mapped to Java Object Types

Since the Java built-in types such as boolean and int are not subtypes of Object, there is
a slightly different mapping from JDBC types to Java object types for the  get/setObject
methods. Notice in the following table instead of  TINYINT and SMALLINT mapping
to the corresponding wrapper class for byte and short, they both map the the Integer
wrapper class.
 
 
 JDBC type   Java type 
 CHAR  String 
 VARCHAR   String
 LONGVARCHAR   String
 NUMERIC  java.math.BigDecimal
 DECIMAL  java.math.BigDecimal
 BIT   Boolean
 TINYINT   Integer
 SMALLINT  Integer
 INTEGER  Integer 
 BIGINT  Long
 REAL  Float
 FLOAT  Double
 DOUBLE   Double
 BINARY   Byte[]
 VARBINARY   Byte[]
 LONGVARBINARY  Byte[]
 DATE   java.sql.Date
 TIME   java.sql.Time
 TIMESTAMP   java.sql.Timestamp

 Java Object Types Mapped to JDBC Types Types

Now we only have the Integer wrapper type that is mapped to SQL Integer.
 
 Java Object Type   JDBC Type
 String  VARCHAR or LONGVARCHAR
 java.math.BigDecimal   NUMERIC
 Boolean  BIT
 Integer  INTEGER
 Long  BIGINT
 Float   REAL
 Double   DOUBLE
 byte[]   VARBINARY or LONGVARBINARY
 java.sql.Date  DATE
 java.sql.Time   TIME
 java.sql.Timestamp    TIMESTAMP

Note, the mapping for String will normally be VARCHAR but will turn into LONGVARCHAR
if the given value exceeds the driver's limit on VARCHAR values. The case is similar for byte[]
and VARBINARY and LONGVARBINARY values.