The PreparedStatement interface provides setter methods that are used to substitute values for each parameter marker of the precompiled SQL string. The names of the methods follow the pattern "set<Type>". The following table defines the allowed setter methods for each of the supported JDBC types. An upper case X marks the recommended setter method for each JDBC type. The invocation of a non-supported (that is, not marked) setter method causes an SQL exception
Use of PreparedStatement setter methods
Type/set<Type>() |
Object |
String |
Boolean |
Bytes |
Byte |
Short |
Int |
Long |
Float |
Double |
BigDecimal |
Date |
Time |
Timestamp |
CharacterStream |
BinaryStream |
Clob |
Blob |
VARCHAR |
x |
X |
|
|
|
|
|
|
|
|
|
|
|
|
x |
|
|
|
LONGVARCHAR |
x |
X |
|
|
|
|
|
|
|
|
|
|
|
|
x |
|
|
|
CLOB |
x |
x |
|
|
|
|
|
|
|
|
|
|
|
|
x |
|
X |
|
BINARY |
x |
|
|
X |
|
|
|
|
|
|
|
|
|
|
|
x |
|
|
LONGVARBINARY |
x |
|
|
X |
|
|
|
|
|
|
|
|
|
|
|
x |
|
|
BLOB |
x |
|
|
x |
|
|
|
|
|
|
|
|
|
|
|
x |
|
X |
SMALLINT |
x |
|
|
|
x |
X |
|
|
|
|
|
|
|
|
|
|
|
|
INTEGER |
x |
|
|
|
x |
x |
X |
|
|
|
|
|
|
|
|
|
|
|
BIGINT |
x |
|
|
|
x |
x |
x |
X |
|
|
|
|
|
|
|
|
|
|
REAL |
x |
|
|
|
x |
x |
x |
x |
X |
|
|
|
|
|
|
|
|
|
DOUBLE |
x |
|
|
|
x |
x |
x |
x |
x |
X |
|
|
|
|
|
|
|
|
DECIMAL |
x |
|
|
|
x |
x |
x |
x |
x |
x |
X |
|
|
|
|
|
|
|
DATE |
x |
|
|
|
|
|
|
|
|
|
|
X |
|
|
|
|
|
|
TIME |
x |
|
|
|
|
|
|
|
|
|
|
|
X |
|
|
|
|
|
TIMESTAMP |
x |
|
|
|
|
|
|
|
|
|
|
|
|
X |
|
|
|
|