@Immutable public 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 }
NOT_EMPTY, UPDATE_COUNT, VOID
Constructor and Description |
---|
SingleOutcome(Class<T> tpe)
Public ctor.
|
SingleOutcome(Class<T> tpe,
boolean slnt)
Public ctor.
|
public SingleOutcome(@NotNull(message="type of result can\'t be NULL") Class<T> tpe)
tpe
- The type to convert to@Loggable(value=1) public T handle(ResultSet rset, Statement stmt) throws SQLException
Outcome
handle
in interface Outcome<T>
rset
- The result set to processstmt
- The statement used in the runSQLException
- If something goes wrong insideCopyright © 2012–2014 jcabi.com. All rights reserved.