Example usage for java.sql PreparedStatement setTimestamp

List of usage examples for java.sql PreparedStatement setTimestamp

Introduction

In this page you can find the example usage for java.sql PreparedStatement setTimestamp.

Prototype

void setTimestamp(int parameterIndex, java.sql.Timestamp x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given java.sql.Timestamp value.

Usage

From source file:iddb.runtime.db.model.dao.impl.mysql.UserDAOImpl.java

@Override
public void savePassKey(String email, String passKey) {
    String sql;/*w  w  w.j a  v  a  2s  .c  o m*/
    sql = "insert into user_pass_rec (loginid, created, passkey) values (?,?,?)";
    Connection conn = null;
    try {
        conn = ConnectionFactory.getMasterConnection();
        PreparedStatement st = conn.prepareStatement(sql);
        st.setString(1, email);
        st.setTimestamp(2, new Timestamp(new Date().getTime()));
        st.setString(3, passKey);
        st.executeUpdate();
    } catch (SQLException e) {
        logger.error("savePassKey: {}", e);
    } catch (IOException e) {
        logger.error("savePassKey: {}", e);
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
    }
}

From source file:iddb.runtime.db.model.dao.impl.mysql.UserDAOImpl.java

@Override
public void change_password(User user) {
    String sql;//from w  w  w  . java 2 s .co  m
    sql = "update user set password = ?, updated = ? where id = ? limit 1";
    Connection conn = null;
    try {
        conn = ConnectionFactory.getMasterConnection();
        PreparedStatement st = conn.prepareStatement(sql);
        st.setString(1, user.getPassword());
        st.setTimestamp(2, new Timestamp(new Date().getTime()));
        st.setLong(3, user.getKey());
        st.executeUpdate();
    } catch (SQLException e) {
        logger.error("Save: {}", e);
    } catch (IOException e) {
        logger.error("Save: {}", e);
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
    }
}

From source file:org.dcache.chimera.H2FsSqlDriver.java

@Override
long createTagInode(int uid, int gid, int mode) {
    final String CREATE_TAG_INODE_WITHOUT_VALUE = "INSERT INTO t_tags_inodes (imode, inlink, iuid, igid, isize, "
            + "ictime, iatime, imtime, ivalue) VALUES (?,1,?,?,0,?,?,?,NULL)";

    Timestamp now = new Timestamp(System.currentTimeMillis());
    KeyHolder keyHolder = new GeneratedKeyHolder();
    int rc = _jdbc.update(con -> {
        PreparedStatement ps = con.prepareStatement(CREATE_TAG_INODE_WITHOUT_VALUE,
                Statement.RETURN_GENERATED_KEYS);
        ps.setInt(1, mode | UnixPermission.S_IFREG);
        ps.setInt(2, uid);/*w ww  .  j  a  v  a 2  s.  co  m*/
        ps.setInt(3, gid);
        ps.setTimestamp(4, now);
        ps.setTimestamp(5, now);
        ps.setTimestamp(6, now);
        return ps;
    }, keyHolder);
    if (rc != 1) {
        throw new JdbcUpdateAffectedIncorrectNumberOfRowsException(CREATE_TAG_INODE_WITHOUT_VALUE, 1, rc);
    }
    /* H2 uses weird names for the column with the auto-generated key, so we cannot use the code
     * in the base class.
     */
    return (Long) keyHolder.getKey();
}

From source file:org.gridobservatory.greencomputing.dao.TimeseriesDao.java

protected void insertTimeSeriesAcquisitions(final BigInteger timeSeriesId,
        final List<TimeseriesAcquisitionType> acquisitions) {
    executor.submit(new Runnable() {
        @Override//from w w w .  j  av  a2 s.  c  om
        public void run() {
            if (acquisitions != null) {
                getJdbcTemplate().batchUpdate(
                        "insert into time_series_acquisition (time_series_id, ts, value) values (?,?,?)",
                        new BatchPreparedStatementSetter() {

                            @Override
                            public void setValues(PreparedStatement ps, int i) throws SQLException {
                                ps.setLong(1, timeSeriesId.longValue());
                                long dateInMilis = acquisitions.get(i).getTs()
                                        .multiply(BigInteger.valueOf(1000l)).longValue();
                                ps.setTimestamp(2, new Timestamp(dateInMilis));
                                ps.setBigDecimal(3, new BigDecimal(acquisitions.get(i).getV()));
                            }

                            @Override
                            public int getBatchSize() {
                                return acquisitions.size();
                            }
                        });
            }
        }
    });
}

From source file:cn.vlabs.duckling.vwb.service.init.provider.DPageInitProvider.java

private DPage createDpage(final int siteId, final DPagePo dpage) {
    final String sql = "insert into vwb_dpage_content_info "
            + "(siteId,resourceid,version,change_time,content,change_by,title) " + " values(?,?,?,?,?,?,?)";
    KeyHolder keyHolder = new GeneratedKeyHolder();
    getJdbcTemplate().update(new PreparedStatementCreator() {
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = conn.prepareStatement(sql);
            int i = 0;
            ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            ps.setInt(++i, siteId);/*from  ww w.  j a v a  2s.  com*/
            ps.setInt(++i, dpage.getResourceId());
            ps.setInt(++i, dpage.getVersion());
            ps.setTimestamp(++i, new Timestamp(dpage.getTime().getTime()));
            ps.setString(++i, dpage.getContent());
            ps.setString(++i, dpage.getCreator());
            ps.setString(++i, dpage.getTitle());
            return ps;
        }
    }, keyHolder);
    dpage.setId(Integer.valueOf(keyHolder.getKey().intValue()));
    return DtoPoConvertor.convertPoToDto(dpage);
}

From source file:com.taobao.diamond.server.service.DBPersistService.java

public void updateConfigInfo(final Timestamp time, final ConfigInfo configInfo) {

    this.jt.update("update config_info set content=?,md5=?,gmt_modified=? where data_id=? and group_id=?",
            new PreparedStatementSetter() {

                public void setValues(PreparedStatement ps) throws SQLException {
                    int index = 1;
                    ps.setString(index++, configInfo.getContent());
                    ps.setString(index++, configInfo.getMd5());
                    ps.setTimestamp(index++, time);
                    ps.setString(index++, configInfo.getDataId());
                    ps.setString(index++, configInfo.getGroup());
                }/*  ww  w.  j  ava2s  .  c  o m*/
            });
}

From source file:nl.ordina.bag.etl.dao.postgres.BAGMutatiesDAOImpl.java

@Override
public void insert(final BAGMutatie mutatie) throws DAOException {
    try {/*from w w  w  .ja  v a 2s  .  co m*/
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                try {
                    PreparedStatement ps = connection.prepareStatement("insert into bag_mutatie (" + "id,"
                            + "tijdstip_verwerking," + "volgnr_verwerking," + "object_type," + "mutatie_product"
                            + ") values ((select coalesce(max(id),0) + 1 from bag_mutatie),?,?,?,?)");
                    ps.setTimestamp(1, Utils.toTimestamp(mutatie.getTijdstipVerwerking()));
                    ps.setLong(2, mutatie.getVolgnrVerwerking());
                    ps.setInt(3, mutatie.getObjectType().ordinal());
                    ps.setString(4, XMLMessageBuilder.getInstance(MutatieProduct.class)
                            .handle(new JAXBElement<MutatieProduct>(new QName(
                                    "http://www.kadaster.nl/schemas/bag-verstrekkingen/extract-producten-lvc/v20090901",
                                    "Mutatie-product"), MutatieProduct.class, mutatie.getMutatieProduct())));
                    return ps;
                } catch (JAXBException e) {
                    throw new DAOException(e);
                }
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

From source file:com.asakusafw.testdriver.TestDriverTestToolsBase.java

private void updateTimestamp(String tableName, String timestampColumn, Timestamp timestamp) {
    LOG.info("{}?{}??????", tableName, timestampColumn);
    Connection conn = null;//from  www .  ja v a2s .com
    PreparedStatement stmt = null;
    try {
        conn = DbUtils.getConnection();
        stmt = conn.prepareStatement(
                MessageFormat.format("UPDATE {0} SET {1} = ? WHERE {1} IS NULL", tableName, timestampColumn));
        stmt.setTimestamp(1, timestamp);
        int rows = stmt.executeUpdate();
        LOG.info("{}?{}?????: {}",
                new Object[] { tableName, timestampColumn, rows });
        if (conn.getAutoCommit() == false) {
            conn.commit();
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DbUtils.closeQuietly(stmt);
        DbUtils.closeQuietly(conn);
    }
}

From source file:pl.edu.agh.iosr.lsf.dao.DatabaseHelper.java

public List<String[]> listTagsActivity(Timestamp from, Timestamp to) throws SQLException {
    try (Connection c = source.getConnection()) {
        PreparedStatement ps = c.prepareStatement(statementStore.get("LIST_TAG_ACTIVITY"));
        ps.setTimestamp(1, from);
        ps.setTimestamp(2, to);/*from ww  w .  j a va 2s. co m*/
        return select(ps);
    }
}

From source file:pl.edu.agh.iosr.lsf.dao.DatabaseHelper.java

public List<String[]> listUsersActivity(Timestamp from, Timestamp to) throws SQLException {
    try (Connection c = source.getConnection()) {
        PreparedStatement ps = c.prepareStatement(statementStore.get("LIST_USER_ACTIVITY"));
        ps.setTimestamp(1, from);
        ps.setTimestamp(2, to);/*w ww.j a v  a2  s.co m*/
        return select(ps);
    }
}