Tuesday, November 6, 2007

Data Type Conversion Tables:JAVA

The tables provided here describe the various mappings and conversions that
drivers must support.
TABLE B-1 JDBC Types Mapped to Java Types
This table shows the conceptual correspondence between JDBC types and Java
types. A programmer should write code with this mapping in mind. For example, if
a value in the database is a SMALLINT, a short should be the data type used in a
JDBC application.
All CallableStatement getter methods except for getObject use this mapping. The
getObject methods for both the CallableStatement and ResultSet interfaces
use the mapping in TABLE B-3.
TABLE B-2 Java Types Mapper to JDBC Types
This table shows the mapping a driver should use for the updater methods in the
ResultSet interface and for IN parameters. PreparedStatement setter
methods and RowSet setter methods use this table for mapping an IN parameter,
which is a Java type, to the JDBC type that will be sent to the database. Note that the
setObject methods for these two interfaces use the mapping shown in TABLE B-4.
TABLE B-3 JDBC Types Mapped to Java Object Types
ResultSet.getObject and CallableStatement.getObject use the mapping
shown in this table for standard mappings.
TABLE B-4 Java Object Types Mapped to JDBC Types
PreparedStatement.setObject and RowSet.setObject use the mapping
shown in this table when no parameter specifying a target JDBC type is provided.
TABLE B-5 Conversions by setObject from Java Obejct Types to JDBC Types
This table shows which JDBC types may be specified as the target JDBC type to the
methods PreparedStatement.setObject and RowSet.setObject.
B-176 JDBC 3.0 • July 2000
TABLE B-6 Type Conversions Supported by ResultSet getter Methods
This table shows which JDBC types may be returned by ResultSet getter methods.
A bold X indicates the method recommended for retrieving a JDBC type. A plain x
indicates for which JDBC types it is possible to use a getter method.
This table also shows the conversions used by the SQLInput reader methods, except
that they use only the recommended conversions.


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
BOOLEAN 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
CLOB Clob
BLOB Blob
ARRAY Array
DISTINCT mapping of underlying type
STRUCT Struct
REF Ref
DATALINK java.net.URL
JAVA_OBJECT underlying Java class



Data Type Conversion
(
Standard Mapping from Java Types to JDBC Types)

JAVA Type JDBC Type


String CHAR, VARCHAR, or LONGVARCHAR
java.math.BigDecimal NUMERIC
boolean BIT or BOOLEAN
byte TINYINT
short SMALLINT
int INTEGER
long BIGINT
float REAL
double DOUBLE
byte[] BINARY, VARBINARY, or
LONGVARBINARY
java.sql.Date DATE
java.sql.Time TIME
java.sql.Timestamp TIMESTAMP
Clob CLOB
Blob BLOB
Array ARRAY
Struct STRUCT
Ref REF
java.net.URL DATALINK
Java class JAVA_OBJECT

No comments: