apache > db
Apache DB Project
 
Font size:      

Use the appropriate getXXX and setXXX methods for the type

Use the appropriate getXXX and setXXX methods for the type

JDBC is permissive. It lets you use java.sql.ResultSet.getFloat to retrieve an int, java.sql.ResultSet.getObject to retrieve any type, and so on. (java.sql.ResultSet and java.sql.CallableStatement provide getXXX methods, and java .sql.PreparedStatement and java.sql.CallableStatement provide setXXX methods.) This permissiveness is convenient but expensive in terms of performance.

For performance reasons, use the recommended getXXX method when retrieving values, and use the recommended setXXX method when setting values for parameters.

Table 2 shows the recommended getXXX methods for given java.sql (JDBC) types, and their corresponding SQL types.

Table 2. Mapping of java.sql.Types to SQL Types

Recommended getXXX Methodjava.sql.Types SQL Types
getLong BIGINTBIGINT
getBytes BINARYCHAR FOR BIT DATA
getString CHARCHAR
getDate DATEDATE
getBigDecimal DECIMALDECIMAL
getDouble DOUBLEDOUBLE PRECISION
getDouble FLOAT DOUBLE PRECISION
getInt INTEGERINTEGER
getBinaryStream LONGVARBINARY LONG VARCHAR FOR BIT DATA
getAsciiStream, getUnicodeStream LONGVARCHAR LONG VARCHAR
getBigDecimal NUMERICDECIMAL
getFloat REALREAL
getShort SMALLINTSMALLINT
getTime TIMETIME
getTimestamp TIMESTAMPTIMESTAMP
getBytes VARBINARYVARCHAR FOR BIT DATA
getString VARCHARVARCHAR
getBlobBLOBBLOB
getClobCLOBCLOB

Previous Page
Next Page
Table of Contents
Index