List of usage examples for java.sql ResultSet getTimestamp
java.sql.Timestamp getTimestamp(String columnLabel) throws SQLException;
ResultSet
object as a java.sql.Timestamp
object in the Java programming language. From source file:ar.com.springbasic.beans.AdminRowMapper.java
@Override public Admin mapRow(ResultSet rs, int i) throws SQLException { Admin admin = new Admin(); admin.setIdAd(rs.getInt("idAd")); admin.setCargo(rs.getString("cargo")); admin.setFechaCreacion(rs.getTimestamp("fechaCreacion")); admin.setNombre(rs.getString("nombre")); return admin; }
From source file:de.whs.poodle.WorksheetAutoUnlockScheduler.java
@Scheduled(fixedRate = RATE_MS) public void unlockWorksheets() { log.info("checking for worksheets to unlock..."); /* query all locked worksheets that have unlock_at in the past, i.e. * all worksheets that need to be unlocked right now. */ jdbc.query(//from w w w.j a v a2 s .c om "SELECT id,unlock_at FROM worksheet " + "WHERE NOT unlocked " + "AND unlock_at IS NOT NULL " + "AND unlock_at <= NOW()", new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { int id = rs.getInt("id"); Date unlockAt = rs.getTimestamp("unlock_at"); log.info("unlocking worksheet {} with unlock_at = {}", id, unlockAt); try { worksheetUnlockEmailService.unlockWorksheetAndSendEmail(id); } catch (MessagingException e) { log.error("failed to send email", e); } } }); }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * select all unique public keys for user * * @param userId user id/* w ww . j av a2s. com*/ * @return public key list for user */ public static List<PublicKey> getUniquePublicKeysForUser(Long userId) { Connection con = null; Map<String, PublicKey> keyMap = new LinkedHashMap(); try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "select * from public_keys where user_id=? and enabled=true order by key_nm asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString(KEY_NM)); publicKey.setPublicKey(rs.getString(PUBLIC_KEY)); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong(PROFILE_ID))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp(CREATE_DT)); keyMap.put(publicKey.getKeyNm() + " (" + publicKey.getFingerprint() + ")", publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return new ArrayList(keyMap.values()); }
From source file:com.tethrnet.manage.db.PublicKeyDB.java
/** * select all unique public keys for user * * @param userId user id// www. ja v a2 s.c o m * @return public key list for user */ public static List<PublicKey> getUniquePublicKeysForUser(Long userId) { Connection con = null; Map<String, PublicKey> keyMap = new LinkedHashMap(); try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement( "select * from public_keys where user_id=? and enabled=true order by key_nm asc"); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString("key_nm")); publicKey.setPublicKey(rs.getString("public_key")); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong("profile_id"))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp("create_dt")); keyMap.put(publicKey.getKeyNm() + " (" + publicKey.getFingerprint() + ")", publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); return new ArrayList(keyMap.values()); }
From source file:com.keybox.manage.db.PublicKeyDB.java
/** * returns public keys based on sort order defined * * @param sortedSet object that defines sort order * @param userId user id/* w w w.ja v a 2 s. c om*/ * @return sorted script list */ public static SortedSet getPublicKeySet(SortedSet sortedSet, Long userId) { ArrayList<PublicKey> publicKeysList = new ArrayList<>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select * from public_keys where user_id = ? and enabled=true " + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString(KEY_NM)); publicKey.setPublicKey(rs.getString(PUBLIC_KEY)); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong(PROFILE_ID))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp(CREATE_DT)); publicKeysList.add(publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(publicKeysList); return sortedSet; }
From source file:com.tethrnet.manage.db.PublicKeyDB.java
/** * returns public keys based on sort order defined * * @param sortedSet object that defines sort order * @param userId user id//w w w . ja v a 2s . co m * @return sorted script list */ public static SortedSet getPublicKeySet(SortedSet sortedSet, Long userId) { ArrayList<PublicKey> publicKeysList = new ArrayList<PublicKey>(); String orderBy = ""; if (sortedSet.getOrderByField() != null && !sortedSet.getOrderByField().trim().equals("")) { orderBy = "order by " + sortedSet.getOrderByField() + " " + sortedSet.getOrderByDirection(); } String sql = "select * from public_keys where user_id = ? and enabled=true " + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); stmt.setLong(1, userId); ResultSet rs = stmt.executeQuery(); while (rs.next()) { PublicKey publicKey = new PublicKey(); publicKey.setId(rs.getLong("id")); publicKey.setKeyNm(rs.getString("key_nm")); publicKey.setPublicKey(rs.getString("public_key")); publicKey.setProfile(ProfileDB.getProfile(con, rs.getLong("profile_id"))); publicKey.setType(SSHUtil.getKeyType(publicKey.getPublicKey())); publicKey.setFingerprint(SSHUtil.getFingerprint(publicKey.getPublicKey())); publicKey.setCreateDt(rs.getTimestamp("create_dt")); publicKeysList.add(publicKey); } DBUtils.closeRs(rs); DBUtils.closeStmt(stmt); } catch (Exception e) { log.error(e.toString(), e); } DBUtils.closeConn(con); sortedSet.setItemList(publicKeysList); return sortedSet; }
From source file:dk.netarkivet.common.utils.DBUtils.java
/** * Get a Date from a column in the resultset. * Returns null, if the value in the column is NULL. * @param rs the resultSet//w w w. ja va 2 s . c om * @param columnIndex The given column, where the Date resides * @return a Date from a column in the resultset * @throws SQLException If columnIndex does not correspond to a * parameter marker in the ResultSet, or a database access error * occurs or this method is called on a closed ResultSet */ public static Date getDateMaybeNull(ResultSet rs, final int columnIndex) throws SQLException { ArgumentNotValid.checkNotNull(rs, "ResultSet rs"); ArgumentNotValid.checkNotNegative(columnIndex, "int columnIndex"); final Timestamp startTimestamp = rs.getTimestamp(columnIndex); if (rs.wasNull()) { return null; } Date startdate; if (startTimestamp != null) { startdate = new Date(startTimestamp.getTime()); } else { startdate = null; } return startdate; }
From source file:edu.pitt.sis.infsci2730.finalProject.utils.TransactionRowMapper.java
public TransactionDBModel mapRow(ResultSet rs, int index) throws SQLException { TransactionDBModel transaction = new TransactionDBModel(); transaction.setTransaction_id(rs.getInt("TRANSACTION_ID")); transaction.setTransaction_date(rs.getTimestamp("TRANSACTION_DATE")); transaction.setCustomer_id(rs.getInt("CUSTOMER_ID")); // transaction.setSalesperson_id(rs.getInt("SALESPERSON_ID")); return transaction; }
From source file:PostGresqlDataSourceTest.java
@Transactional(readOnly = true) public void executeGoodSQL() { try {//w ww. j a v a 2 s. co m jdbc.query("select NOW()", new RowCallbackHandler() { @Override public void processRow(final ResultSet rs) throws SQLException { log.info("testConnection(): NOW() = {}", rs.getTimestamp(1)); } }); } catch (final Exception e) { throw new RuntimeException(e); } }
From source file:com.persistent.cloudninja.mapper.InstanceHealthActiveUserRowMapper.java
@Override public InstanceHealthActiveUserEntity mapRow(ResultSet rs, int rowNum) throws SQLException { InstanceHealthActiveUserEntity uniqueUser = new InstanceHealthActiveUserEntity(); uniqueUser.setCount(rs.getInt("ActiveUsers")); Timestamp time = rs.getTimestamp("TimeInterval"); uniqueUser.setTimeStamp(new Date(time.getTime())); return uniqueUser; }