Java Reference
In-Depth Information
Table 5-2: Standard Mapping from SQL Types to Java
SQL type
Java type
Description
LONGVARCHAR
String
Variable-length character string. JDBC allows
retrieval of a LONGVARCHAR as a Java input
stream.
NUMERIC
java.math.BigDecimal
Arbitrary-precision signed decimal numbers. Can
be retrieved using either BigDecimal or String.
DECIMAL
java.math.BigDecimal
Arbitrary-precision signed decimal numbers. Can
be retrieved using either BigDecimal or String.
BIT
boolean
Yes/No value
TINYINT
byte
8 bit integer values
SMALLINT
short
16 bit integer values
INTEGER
int
32 bit integer values
BIGINT
long
64 bit integer values
REAL
float
Floating point number, mapped to float
FLOAT
double
Floating point number, mapped to double
DOUBLE
double
Floating point number, mapped to double
BINARY
byte[]
Retrieve as byte array
VARBINARY
byte[]
Retrieve as byte array
LONGVARBINARY
byte[]
Retrieve as byte array. JDBC allows retrieval of a
LONGVARCHAR as a Java input stream.
DATE
java.sql.Date
Thin wrapper around java.util.Date
TIME
java.sql.Time
Thin wrapper around java.util.Date
TIMESTAMP
java.sql.Timestamp
Composite of a java.util.Date and a separate
nanosecond value
As you can see from Table 5-2 , most of the fields we will be using can be handled using the VARCHAR
type. The zip code is perhaps also best handled using a VARCHAR, since we will not be using it for
arithmetic; nine-digit zips are frequently entered with a hyphen as a separator.
Note
VARCHAR is preferrable to CHARACTER because when you use CHARACTER(n), the
DBMS always assigns n characters to the field, padding the field to fill unallocated space;
when you use VARCHAR(n), the DBMS assigns up to n characters, as required.
Integrity Constraints
Search WWH ::




Custom Search