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:PostGresqlDataSourceTest.java
@Transactional @Test/*from w ww.j a v a2 s .c o m*/ public void testConnection() { try { for (int i = 0; i < 100; i++) { 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.keybox.manage.db.PublicKeyDB.java
/** * returns public keys based on sort order defined * * @param sortedSet object that defines sort order * @return sorted script list// w ww. ja v a 2 s.c o m */ public static SortedSet getPublicKeySet(SortedSet sortedSet) { 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 p.*, u.username from public_keys p, users u where u.id=p.user_id "; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID)) ? " and p.user_id=? " : ""; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID)) ? " and p.profile_id=? " : ""; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_ENABLED)) ? " and p.enabled=? " : " and p.enabled=true"; sql = sql + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); int i = 1; //set filters in prepared statement if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))) { stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))); } if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))) { stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))); } if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_ENABLED))) { stmt.setBoolean(i, Boolean.valueOf(sortedSet.getFilterMap().get(FILTER_BY_ENABLED))); } 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)); publicKey.setUsername(rs.getString("username")); publicKey.setUserId(rs.getLong("user_id")); publicKey.setEnabled(rs.getBoolean("enabled")); 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 * @return sorted script list/*from w w w. j a v a 2s .c o m*/ */ public static SortedSet getPublicKeySet(SortedSet sortedSet) { 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 p.*, u.username from public_keys p, users u where u.id=p.user_id "; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID)) ? " and p.user_id=? " : ""; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID)) ? " and p.profile_id=? " : ""; sql += StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_ENABLED)) ? " and p.enabled=? " : " and p.enabled=true"; sql = sql + orderBy; Connection con = null; try { con = DBUtils.getConn(); PreparedStatement stmt = con.prepareStatement(sql); int i = 1; //set filters in prepared statement if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))) { stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_USER_ID))); } if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))) { stmt.setLong(i++, Long.valueOf(sortedSet.getFilterMap().get(FILTER_BY_PROFILE_ID))); } if (StringUtils.isNotEmpty(sortedSet.getFilterMap().get(FILTER_BY_ENABLED))) { stmt.setBoolean(i++, Boolean.valueOf(sortedSet.getFilterMap().get(FILTER_BY_ENABLED))); } 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")); publicKey.setUsername(rs.getString("username")); publicKey.setUserId(rs.getLong("user_id")); publicKey.setEnabled(rs.getBoolean("enabled")); 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.test.springmvc.springmvcproject.mapper.CommentMapper.java
@Override public CommentaireBoBean mapRow(ResultSet rs, int i) throws SQLException { final CommentaireBoBean commentaire = new CommentaireBoBean(); commentaire.setCommentaire(rs.getString("commentaire")); commentaire.setDate_commentaire(rs.getTimestamp("date_commentaire")); final UtilisateurBean utilisateur = new UtilisateurBean(); utilisateur.setId(rs.getInt("user_id")); utilisateur.setUsertag(rs.getString("user_usertag")); commentaire.setUtilisateur(utilisateur); final BookBoBean livre = new BookBoBean(); livre.setId(rs.getInt("livre_id")); commentaire.setLivre(livre);/*from ww w.j a v a 2s. co m*/ return commentaire; }
From source file:org.jasig.schedassist.impl.owner.PersistenceAvailableBlockRowMapper.java
public PersistenceAvailableBlock mapRow(ResultSet rs, int rowNum) throws SQLException { PersistenceAvailableBlock schedule = new PersistenceAvailableBlock(); schedule.setOwnerId(rs.getLong("owner_id")); schedule.setStartTime(rs.getTimestamp("start_time")); schedule.setEndTime(rs.getTimestamp("end_time")); int visitorLimit = rs.getInt("visitor_limit"); if (visitorLimit == 0) { // visitor_limit column empty (undefined), set default (1) visitorLimit = 1;/*from w ww . ja va 2 s .co m*/ } schedule.setVisitorLimit(visitorLimit); schedule.setMeetingLocation(rs.getString("meeting_location")); return schedule; }
From source file:org.xeneo.db.recommendation.DBEntryRowMapper.java
@Override public Object mapRow(ResultSet rs, int rowNum) throws SQLException { DBEntry dbEntry = new DBEntry(); dbEntry.setCaseTypeUri(rs.getString("CaseTypeURI")); dbEntry.setTaskUri(rs.getString("TaskURI")); dbEntry.setCreationDate(rs.getTimestamp("CreationDate")); return dbEntry; }
From source file:eu.databata.engine.dao.PropagationHistoryRowMapper.java
@Override public PropagationHistory mapRow(ResultSet rs, int rowNum) throws SQLException { PropagationHistory history = new PropagationHistory(); history.setModuleName(rs.getString("module_name")); history.setCode(rs.getString("code")); history.setChangeTime(rs.getTimestamp("change_time")); return history; }
From source file:ru.mystamps.web.dao.impl.UsersActivationRowMapper.java
@Override public UsersActivation mapRow(ResultSet resultSet, int i) throws SQLException { String activationKey = resultSet.getString("act_key"); String email = resultSet.getString("email"); String lang = resultSet.getString("lang"); Date createdAt = resultSet.getTimestamp("created_at"); return new UsersActivation(activationKey, email, lang, createdAt); }
From source file:com.monkeyk.sos.infrastructure.jdbc.UserRowMapper.java
@Override public User mapRow(ResultSet rs, int i) throws SQLException { User user = new User(); user.id(rs.getInt("id")); user.guid(rs.getString("guid")); user.archived(rs.getBoolean("archived")); user.createTime(rs.getTimestamp("create_time").toLocalDateTime()); user.email(rs.getString("email")); user.phone(rs.getString("phone")); user.password(rs.getString("password")); user.username(rs.getString("username")); user.lastLoginTime(rs.getTimestamp("last_login_time")); return user;//from ww w . j a v a 2s .com }
From source file:org.surfnet.cruncher.message.AggregatorTest.java
@Test public void testRun() { aggregator.run();// www .ja v a2 s .c om Calendar instance = Calendar.getInstance(); instance.set(2012, 3, 21); String hash = aggregationRecordHash("idp2", "sp1", instance.getTime()); long entryCount = cruncherJdbcTemplate .queryForLong("select entrycount from aggregated_log_logins where datespidphash = ?", hash); assertEquals(2, entryCount); long timestamp = cruncherJdbcTemplate.queryForLong("select aggregatepoint from aggregate_meta_data"); assertEquals(20009L, timestamp); String userHash = aggregationRecordHash("idp2:user_1", "sp1"); long lastlogin = cruncherJdbcTemplate.queryForObject( "select loginstamp from user_log_logins where usersphash = '" + userHash + "'", new RowMapper<Long>() { @Override public Long mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getTimestamp(1).getTime(); } }); instance.setTimeInMillis(lastlogin); //2012-02-20 11:48:42 assertEquals(20, instance.get(DAY_OF_MONTH)); assertEquals(1, instance.get(MONDAY)); assertEquals(2012, instance.get(YEAR)); }