Package com.jcabi.jdbc
Class Utc
- java.lang.Object
-
- com.jcabi.jdbc.Utc
-
public final class Utc extends Object
UTC time zone manipulator.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); } } );Timestampis used becauseDatesupports only dates (without time).- Since:
- 0.1.8
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DategetDate()Get date that is encapsulated.static DategetTimestamp(ResultSet rset, int pos)Retrieve timestamp from the result set.voidsetTimestamp(PreparedStatement stmt, int pos)Convert date to timestamp and save to the statement.
-
-
-
Constructor Detail
-
Utc
public Utc()
Public ctor, with current date.
-
Utc
public Utc(Date when)
Public ctor.- Parameters:
when- The date to use.
-
-
Method Detail
-
getDate
public Date getDate()
Get date that is encapsulated.- Returns:
- The date
-
setTimestamp
public void setTimestamp(PreparedStatement stmt, int pos) throws SQLException
Convert date to timestamp and save to the statement.- Parameters:
stmt- The statementpos- Position in the statement- Throws:
SQLException- If some SQL problem inside
-
getTimestamp
public static Date getTimestamp(ResultSet rset, int pos) throws SQLException
Retrieve timestamp from the result set.- Parameters:
rset- The result setpos- Position in the result set- Returns:
- The date
- Throws:
SQLException- If some SQL problem inside
-
-