Java Reference
In-Depth Information
Finding JDBC Metadata
. SQL handles many types of data, and JDBC offers corresponding
Table 18-3. Data type mappings between SQL and JDBC
JDBC method SQL type
Java type
BIT
getBit( )
boolean
TINYINT
getByte( )
byte
SMALLINT
getShort( )
short
INTEGER
getInt( )
int
BIGINT
getLong( )
long
REAL
getFloat( )
float
DOUBLE
getDouble( )
double
CHAR
getString( )
String
VARCHAR
getString( )
String
LONGVARCHAR
String
getString( )
DATE
getDate( )
java.sql.Date
TIME
getTimeStamp()
java.sql.Date
BLOB
getObject( )
Object
Assuming that we have a relational database containing the
User
data, we can retrieve it as
demonstrated in
Example 18-5
.
This program retrieves any or all entries that have a user-
name of
ian
and prints the
ResultSet
s in a loop. It prints lines like:
User ian is named Ian Darwin
The source code is shown in
Example 18-5
.