@Immutable public final class Utc extends Object
When it's necessary to save date/time to the DB in UTC timezone, use this class:
new JdbcSession(source)
.sql("INSERT INTO payment (amount, date) VALUES (?, ?)")
.set(500)
.set(new Utc()) // current date to be set, in UTC timezone
.insert(Outcome.VOID);
This class also helps during date/time retrieval:
Date date = new JdbcSession(source)
.sql("SELECT date FROM payment WHERE id = 555")
.select(
new Outcome<Date>() {
@Override
public Date handle(final ResultSet rset) throws SQLException {
return Utc.getTimestamp(rset, 1);
}
}
);
Timestamp is used because Date
supports only dates (without time).
| Constructor and Description |
|---|
Utc()
Public ctor, with current date.
|
Utc(Date when)
Public ctor.
|
| Modifier and Type | Method and Description |
|---|---|
Date |
getDate()
Get date that is encapsulated.
|
static Date |
getTimestamp(ResultSet rset,
int pos)
Retrieve timestamp from the result set.
|
void |
setTimestamp(PreparedStatement stmt,
int pos)
Convert date to timestamp and save to the statement.
|
@Loggable(value=1) public void setTimestamp(PreparedStatement stmt, int pos) throws SQLException
stmt - The statementpos - Position in the statementSQLException - If some SQL problem inside@Loggable(value=1) public static Date getTimestamp(ResultSet rset, int pos) throws SQLException
rset - The result setpos - Position in the result setSQLException - If some SQL problem insideCopyright © 2012–2014 jcabi.com. All rights reserved.