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:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

protected void insertGebruikersdoelen(final List<Verblijfsobject> verblijfsobjecten) {
    final List<Gebruiksdoel> batch = new ArrayList<Gebruiksdoel>();
    for (Verblijfsobject verblijfsobject : verblijfsobjecten)
        for (nl.kadaster.schemas.imbag.imbag_types.v20090901.Gebruiksdoel gebruiksdoel : verblijfsobject
                .getGebruiksdoelenVerblijfsobject())
            batch.add(new Gebruiksdoel(verblijfsobject, gebruiksdoel));
    jdbcTemplate.batchUpdate(// w  w  w .j av a 2 s  . c  o  m
            "insert into bag_gebruiksdoel (" + "bag_verblijfsobject_id," + "aanduiding_record_correctie,"
                    + "begindatum_tijdvak_geldigheid," + "gebruiksdoel" + ") values (?,?,?,?)",
            new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    ps.setLong(1, batch.get(i).getIdentificatie());
                    ps.setLong(2, batch.get(i).getAanduidingRecordCorrectie());
                    ps.setTimestamp(3, new Timestamp(batch.get(i).getBegindatumTijdvakGeldigheid().getTime()));
                    ps.setInt(4, batch.get(i).getGebruiksdoel().ordinal());
                }

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

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

protected void insertNevenadressen(final TypeAdresseerbaarObject objectType,
        final List<? extends BAGAdresseerbaarObject> objects) {
    final List<NevenAdres> batch = new ArrayList<NevenAdres>();
    for (BAGAdresseerbaarObject object : objects)
        for (Long nevenAdres : object.getNevenAdressen())
            batch.add(new NevenAdres(object, nevenAdres));
    jdbcTemplate.batchUpdate("insert into bag_neven_adres (" + "bag_object_id," + "aanduiding_record_correctie,"
            + "begindatum_tijdvak_geldigheid," + "bag_object_type," + "bag_nummeraanduiding_id"
            + ") values (?,?,?,?,?)", new BatchPreparedStatementSetter() {
                @Override/*from w  ww .  j  a  v a  2s.co  m*/
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    ps.setLong(1, batch.get(i).getIdentificatie());
                    ps.setLong(2, batch.get(i).getAanduidingRecordCorrectie());
                    ps.setTimestamp(3, new Timestamp(batch.get(i).getBegindatumTijdvakGeldigheid().getTime()));
                    ps.setInt(4, objectType.ordinal());
                    ps.setLong(5, batch.get(i).getNevenAdres());
                }

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

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

protected void deleteGebruikersdoelen(final Verblijfsobject verblijfsobject) {
    jdbcTemplate.batchUpdate(//from  w  w  w  .  j a v  a  2  s . c  om
            "delete from bag_gebruiksdoel" + " where bag_verblijfsobject_id = ?"
                    + " and aanduiding_record_correctie = ?" + " and begindatum_tijdvak_geldigheid = ?",
            new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    ps.setLong(1, verblijfsobject.getIdentificatie());
                    ps.setLong(2, verblijfsobject.getAanduidingRecordCorrectie());
                    ps.setTimestamp(3,
                            new Timestamp(verblijfsobject.getBegindatumTijdvakGeldigheid().getTime()));
                }

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

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

protected void insertGebruikersdoelen(final Verblijfsobject verblijfsobject) {
    jdbcTemplate.batchUpdate(/*  w ww.  j a  v  a  2s.  c o m*/
            "insert into bag_gebruiksdoel (" + "bag_verblijfsobject_id," + "aanduiding_record_correctie,"
                    + "begindatum_tijdvak_geldigheid," + "gebruiksdoel" + ") values (?,?,?,?)",
            new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    ps.setLong(1, verblijfsobject.getIdentificatie());
                    ps.setLong(2, verblijfsobject.getAanduidingRecordCorrectie());
                    ps.setTimestamp(3,
                            new Timestamp(verblijfsobject.getBegindatumTijdvakGeldigheid().getTime()));
                    ps.setInt(4, verblijfsobject.getGebruiksdoelenVerblijfsobject().get(i).ordinal());
                }

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

From source file:nl.ordina.bag.etl.dao.AbstractBAGDAO.java

protected void insertGerelateerdePanden(final Verblijfsobject verblijfsobject) {
    jdbcTemplate.batchUpdate(//from w  w w  .ja  v  a 2s .  c o  m
            "insert into bag_gerelateerd_pand (" + "bag_verblijfsobject_id," + "aanduiding_record_correctie,"
                    + "begindatum_tijdvak_geldigheid," + "bag_pand_id" + ") values (?,?,?,?)",
            new BatchPreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps, int i) throws SQLException {
                    ps.setLong(1, verblijfsobject.getIdentificatie());
                    ps.setLong(2, verblijfsobject.getAanduidingRecordCorrectie());
                    ps.setTimestamp(3,
                            new Timestamp(verblijfsobject.getBegindatumTijdvakGeldigheid().getTime()));
                    ps.setLong(4, verblijfsobject.getGerelateerdPanden().get(i));
                }

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

From source file:com.concursive.connect.web.modules.documents.dao.FileItem.java

/**
 * Description of the Method//from w  ww .  j  a  v a 2s .c  o m
 *
 * @param db Description of the Parameter
 * @return Description of the Return Value
 * @throws SQLException Description of the Exception
 */
public boolean enable(Connection db) throws SQLException {
    if (this.getId() == -1) {
        throw new SQLException("File ID not specified");
    }
    boolean success = false;
    int i = 0;
    PreparedStatement pst = db.prepareStatement("UPDATE project_files " + "SET enabled = "
            + DatabaseUtils.getTrue(db) + " " + "WHERE item_id = ? " + "AND modified = ? ");
    pst.setInt(++i, this.getId());
    pst.setTimestamp(++i, this.getModified());
    int resultCount = pst.executeUpdate();
    pst.close();
    if (resultCount == 1) {
        success = true;
    }
    return success;
}

From source file:com.concursive.connect.web.modules.documents.dao.FileItem.java

/**
 * Description of the Method//from   ww  w. ja v  a  2  s .co  m
 *
 * @param db Description of the Parameter
 * @return Description of the Return Value
 * @throws SQLException Description of the Exception
 */
public boolean disable(Connection db) throws SQLException {
    if (this.getId() == -1) {
        throw new SQLException("File ID not specified");
    }
    boolean success = false;
    int i = 0;
    PreparedStatement pst = db.prepareStatement("UPDATE project_files SET " + "enabled = "
            + DatabaseUtils.getFalse(db) + " " + "WHERE item_id = ? " + "AND modified = ? ");
    pst.setInt(++i, this.getId());
    pst.setTimestamp(++i, this.getModified());
    int resultCount = pst.executeUpdate();
    pst.close();
    if (resultCount == 1) {
        success = true;
    }
    return success;
}

From source file:gov.nih.nci.cadsr.persist.de.Data_Elements_Mgr.java

/**
 * Inserts a single row of Data Element in data_elements_view table and returns primary key de_IDSEQ
 * /*from w  w w. java2s.com*/
 * @param deVO
 * @param conn
 * @return
 * @throws DBException
 */
public String insert(BaseVO vo, Connection conn) throws DBException {
    DeVO deVO = (DeVO) vo;
    PreparedStatement statement = null;
    String primaryKey = null;
    // generate de_IDSEQ(primary key) 
    deVO.setDe_IDSEQ(this.generatePrimaryKey(conn));
    deVO.setDeleted_ind(DBConstants.RECORD_DELETED_NO);
    deVO.setDate_created(new java.sql.Timestamp(new java.util.Date().getTime()));
    try {
        String sql = "insert into data_elements_view ( de_idseq, version, conte_idseq, preferred_name, vd_idseq, dec_idseq, "
                + "preferred_definition, asl_name, long_name, latest_version_ind, deleted_ind, "
                + "date_created, begin_date, created_by, end_date, date_modified, modified_by, change_note, origin) "
                + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        int column = 0;
        statement = conn.prepareStatement(sql);
        statement.setString(++column, deVO.getDe_IDSEQ());
        statement.setDouble(++column, deVO.getVersion());
        statement.setString(++column, deVO.getConte_IDSEQ());
        statement.setString(++column, deVO.getPrefferred_name());
        statement.setString(++column, deVO.getVd_IDSEQ());
        statement.setString(++column, deVO.getDec_IDSEQ());
        statement.setString(++column, deVO.getPrefferred_def());
        statement.setString(++column, deVO.getAsl_name());
        statement.setString(++column, deVO.getLong_name());
        statement.setString(++column, deVO.getLastest_version_ind());
        statement.setString(++column, deVO.getDeleted_ind());
        statement.setTimestamp(++column, deVO.getDate_created());
        statement.setTimestamp(++column, deVO.getBegin_date());
        statement.setString(++column, deVO.getCreated_by());
        statement.setTimestamp(++column, deVO.getEnd_date());
        statement.setTimestamp(++column, deVO.getDate_modified());
        statement.setString(++column, deVO.getModified_by());
        statement.setString(++column, deVO.getChange_note());
        statement.setString(++column, deVO.getOrigin());

        int count = statement.executeUpdate();
        if (count == 0) {
            throw new Exception("Unable to insert the record");
        } else {
            primaryKey = deVO.getDe_IDSEQ();
            if (logger.isDebugEnabled()) {
                logger.debug("Inserted DE");
                logger.debug("de_IDSEQ(primary key )-----> " + primaryKey);
            }
        }

    } catch (Exception e) {
        logger.error("Error inserting Data Element " + e);
        errorList.add(DeErrorCodes.API_DE_500);
        throw new DBException(errorList);
    } finally {
        statement = SQLHelper.closePreparedStatement(statement);
    }
    return primaryKey;
}

From source file:chh.utils.db.source.common.JdbcClient.java

private void setPreparedStatementParams(PreparedStatement preparedStatement, List<Column> columnList)
        throws SQLException {
    int index = 1;
    for (Column column : columnList) {
        Class columnJavaType = Util.getJavaType(column.getSqlType());
        if (column.getVal() == null) {
            preparedStatement.setNull(index, column.getSqlType());
        } else if (columnJavaType.equals(String.class)) {
            preparedStatement.setString(index, (String) column.getVal());
        } else if (columnJavaType.equals(Integer.class)) {
            preparedStatement.setInt(index, (Integer) column.getVal());
        } else if (columnJavaType.equals(Double.class)) {
            preparedStatement.setDouble(index, (Double) column.getVal());
        } else if (columnJavaType.equals(Float.class)) {
            preparedStatement.setFloat(index, (Float) column.getVal());
        } else if (columnJavaType.equals(Short.class)) {
            preparedStatement.setShort(index, (Short) column.getVal());
        } else if (columnJavaType.equals(Boolean.class)) {
            preparedStatement.setBoolean(index, (Boolean) column.getVal());
        } else if (columnJavaType.equals(byte[].class)) {
            preparedStatement.setBytes(index, (byte[]) column.getVal());
        } else if (columnJavaType.equals(Long.class)) {
            preparedStatement.setLong(index, (Long) column.getVal());
        } else if (columnJavaType.equals(Date.class)) {
            preparedStatement.setDate(index, (Date) column.getVal());
        } else if (columnJavaType.equals(Time.class)) {
            preparedStatement.setTime(index, (Time) column.getVal());
        } else if (columnJavaType.equals(Timestamp.class)) {
            preparedStatement.setTimestamp(index, (Timestamp) column.getVal());
        } else {/*from  w w  w . j a v a  2 s  .  co  m*/
            throw new RuntimeException(
                    "Unknown type of value " + column.getVal() + " for column " + column.getColumnName());
        }
        ++index;
    }
}

From source file:fr.aliacom.obm.common.contact.ContactDaoJdbcImpl.java

@Override
public int markUpdated(int databaseId) throws SQLException {
    Connection con = null;//  ww w.j a v  a2 s.co m
    PreparedStatement st = null;
    try {
        con = obmHelper.getConnection();
        st = con.prepareStatement("update Contact SET contact_timeupdate=? WHERE contact_id=?");
        st.setTimestamp(1, new Timestamp(obmHelper.selectNow(con).getTime()));
        st.setInt(2, databaseId);
        st.execute();
    } finally {
        obmHelper.cleanup(con, st, null);
    }
    return databaseId;
}