public final class SingleHandler<T> extends Object implements JdbcSession.Handler<T>
Use it when you need the first column in the first row:
Long id = new JdbcSession(source)
.sql("SELECT id FROM user WHERE name = ?")
.set("Jeff Lebowski")
.select(new SingleHandler<Long>(Long.class));
Supported types are: String, Long, Boolean,
Byte, Date, and Utc.
By default, the handler throws SQLException if no records
are found in the ResultSet. You can change this behavior by using
a two-arguments constructor (null will be returned if
ResultSet is empty):
String name = new JdbcSession(source)
.sql("SELECT name FROM user WHERE id = ?")
.set(555)
.select(new SingleHandler<Long>(Long.class), true);
if (name == null) {
// such a record wasn't found in the database
}
This class is thread-safe.
| Constructor and Description |
|---|
SingleHandler(Class<T> tpe)
Public ctor.
|
SingleHandler(Class<T> tpe,
boolean slnt)
Public ctor.
|
public SingleHandler(Class<T> tpe)
tpe - The type to convert topublic T handle(ResultSet rset) throws SQLException
handle in interface JdbcSession.Handler<T>rset - The result set to processSQLException - If something goes wrong insideCopyright © 2012 jcabi.com. All Rights Reserved.