T - Type of itemspublic final class SingleOutcome<T> extends Object implements Outcome<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 SingleOutcome<Long>(Long.class));
Supported types are: String, Long, Boolean,
Byte, Date, and Utc.
By default, the outcome 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 SingleOutcome<Long>(Long.class), true);
if (name == null) {
// such a record wasn't found in the database
}LAST_INSERT_ID, NOT_EMPTY, UPDATE_COUNT, VOID| Constructor and Description |
|---|
SingleOutcome(Class<T> tpe)
Public ctor.
|
SingleOutcome(Class<T> tpe,
boolean slnt)
Public ctor.
|
| Modifier and Type | Method and Description |
|---|---|
T |
handle(ResultSet rset,
Statement stmt)
Process the result set and return some value.
|
public SingleOutcome(Class<T> tpe)
tpe - The type to convert topublic T handle(ResultSet rset, Statement stmt) throws SQLException
Outcomehandle in interface Outcome<T>rset - The result set to processstmt - The statement used in the runSQLException - If something goes wrong insideCopyright © 2012–2019 jcabi.com. All rights reserved.