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:com.alfaariss.oa.engine.session.jdbc.JDBCSessionFactory.java

/**
 * Remove all expired sessions./*from   www . j  a  va2s.  co m*/
 * 
 * e.g. <code>DELETE FROM session WHERE expiration <= NOW()</code>
 * @see ICleanable#removeExpired()
 */
public void removeExpired() throws PersistenceException {
    //DD does not log a user event when session is expired, because this will cost an unnecesary select (eventlogging should be done with DB trigger)
    Connection oConnection = null;
    PreparedStatement ps = null;
    try {
        oConnection = _oDataSource.getConnection();
        ps = oConnection.prepareStatement(_sRemoveExpiredQuery);
        ps.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
        int i = ps.executeUpdate();
        if (i > 0)
            _logger.info(i + " session(s) expired");
    } catch (SQLException e) {
        _logger.error("Could not execute delete expired", e);
        throw new PersistenceException(SystemErrors.ERROR_RESOURCE_REMOVE);
    } catch (Exception e) {
        _logger.error("Internal error while delete expired sessions", e);
        throw new PersistenceException(SystemErrors.ERROR_RESOURCE_REMOVE);
    } finally {
        try {
            if (ps != null)
                ps.close();
        } catch (SQLException e) {
            _logger.debug("Could not close statement", e);
        }
        try {
            if (oConnection != null)
                oConnection.close();
        } catch (SQLException e) {
            _logger.debug("Could not close connection", e);
        }
    }
}

From source file:net.mindengine.oculus.frontend.service.runs.JdbcTestRunDAO.java

@Override
public Long createTestRun(TestRun testRun) throws Exception {
    PreparedStatement ps = getConnection().prepareStatement("insert into test_runs " + "(suite_run_id, "
            + "test_id, " + "start_time, " + "end_time, " + "reasons, " + "report, " + "name, " + "status, "
            + "project_id, description) " + "values (?,?,?,?,?,?,?,?,?,?)");

    if (testRun.getReasons() == null) {
        testRun.setReasons("");
    }//w ww .ja  v a  2 s . com
    if (testRun.getName() == null) {
        testRun.setName("");
    }

    if (testRun.getSuiteRunId() == null) {
        testRun.setSuiteRunId(0L);
    }

    ps.setLong(1, testRun.getSuiteRunId());
    ps.setLong(2, testRun.getTestId());
    ps.setTimestamp(3, new Timestamp(testRun.getStartTime().getTime()));
    ps.setTimestamp(4, new Timestamp(testRun.getEndTime().getTime()));
    ps.setString(5, testRun.getReasons());
    ps.setString(6, testRun.getReport());
    ps.setString(7, testRun.getName());
    ps.setString(8, testRun.getStatus());
    ps.setLong(9, testRun.getProjectId());
    ps.setString(10, testRun.getDescription());
    logger.info(ps);
    ps.execute();

    ResultSet rs = ps.getGeneratedKeys();
    if (rs.next()) {
        return rs.getLong(1);
    }

    return null;
}

From source file:nl.nn.adapterframework.statistics.jdbc.StatisticsKeeperStore.java

public void handleScalar(Object data, String scalarName, Date value) throws SenderException {
    SessionInfo sessionInfo = (SessionInfo) data;
    PreparedStatement stmt = null;

    int statnamekey = -1;
    try {/*from  ww w  .  j  a  v  a 2  s.  c  o m*/
        statnamekey = statnames.findOrInsert(sessionInfo.connection, scalarName);
        if (trace && log.isDebugEnabled())
            log.debug("prepare and execute query [" + insertTimestampQuery + "] params [" + sessionInfo.eventKey
                    + "," + sessionInfo.groupKey + "," + statnamekey + ","
                    + (value == null ? "null" : DateUtils.format(value)) + "]");
        stmt = sessionInfo.connection.prepareStatement(insertTimestampQuery);
        stmt.setLong(1, sessionInfo.eventKey);
        stmt.setLong(2, sessionInfo.groupKey);
        stmt.setLong(3, statnamekey);
        if (value == null) {
            stmt.setNull(4, Types.TIMESTAMP);
        } else {
            stmt.setTimestamp(4, new Timestamp(value.getTime()));
        }
        stmt.execute();
    } catch (Exception e) {
        throw new SenderException("could not execute query [" + insertTimestampQuery + "] params ["
                + sessionInfo.eventKey + "," + sessionInfo.groupKey + "," + statnamekey + ","
                + (value == null ? "null" : DateUtils.format(value)) + "]", e);
    } finally {
        if (stmt != null) {
            try {
                stmt.close();
            } catch (Exception e) {
                throw new SenderException("could not close statement for query [" + insertTimestampQuery
                        + "] params [" + sessionInfo.eventKey + "," + sessionInfo.groupKey + "," + statnamekey
                        + "," + (value == null ? "null" : DateUtils.format(value)) + "]", e);
            }
        }
    }
}

From source file:org.eevolution.form.VCRP.java

int getLoad(int S_Resource_ID, Timestamp start, Timestamp end) {
    int load = 0;

    String sql = "SELECT SUM( CASE WHEN ow.DurationUnit = 's'  THEN 1 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'm' THEN 60 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'h'  THEN 3600 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'Y'  THEN 31536000 *  (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'M' THEN 2592000 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'D' THEN 86400 END ) AS Load FROM MPC_Order_Node onode INNER JOIN MPC_Order_Workflow ow ON (ow.MPC_Order_Workflow_ID =  onode.MPC_Order_Workflow_ID) INNER JOIN MPC_Order o ON (o.MPC_Order_ID = onode.MPC_Order_ID)  WHERE onode.S_Resource_ID = ?  AND onode.AD_Client_ID = ? AND  trunc(?) BETWEEN trunc(onode.DateStartSchedule) AND trunc(onode.DateFinishSchedule)";

    String sql2 = "SELECT SUM( CASE WHEN ow.DurationUnit = 's'  THEN 1 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'm' THEN 60 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'h'  THEN 3600 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'Y'  THEN 31536000 *  (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'M' THEN 2592000 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'D' THEN 86400 END ) AS Load FROM MPC_Order_Node onode INNER JOIN MPC_Order_Workflow ow ON (ow.MPC_Order_Workflow_ID =  onode.MPC_Order_Workflow_ID) INNER JOIN MPC_Order o ON (o.MPC_Order_ID = onode.MPC_Order_ID)  WHERE onode.S_Resource_ID = ?  AND onode.AD_Client_ID = ? AND  trunc('"
            + start + "') BETWEEN trunc(onode.DateStartSchedule) AND trunc(onode.DateFinishSchedule)";

    //String sql = "SELECT SUM( CASE WHEN ow.DurationUnit = 's'  THEN 1 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'm' THEN 60 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'h'  THEN 3600 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'Y'  THEN 31536000 *  (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'M' THEN 2592000 * (onode.QueuingTime + onode.SetupTime + (onode.Duration * (o.QtyOrdered - o.QtyDelivered - o.QtyScrap)) + onode.MovingTime + onode.WaitingTime) WHEN ow.DurationUnit = 'D' THEN 86400 END ) AS Load FROM MPC_Order_Node onode INNER JOIN MPC_Order_Workflow ow ON (ow.MPC_Order_Workflow_ID =  onode.MPC_Order_Workflow_ID) INNER JOIN MPC_Order o ON (o.MPC_Order_ID = onode.MPC_Order_ID)  WHERE onode.S_Resource_ID = ?  AND onode.AD_Client_ID = ? AND  trunc(onode.DateStartSchedule) = ?" ;
    System.out.println("SQL SUM :" + sql2);
    try {//ww  w  .ja  va 2  s  .c  o  m
        PreparedStatement pstmt = null;
        pstmt = DB.prepareStatement(sql);
        pstmt.setInt(1, S_Resource_ID);
        pstmt.setInt(2, AD_Client_ID);
        pstmt.setTimestamp(3, start);
        System.out.println("Params SQL :" + S_Resource_ID + " " + AD_Client_ID + " " + start);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            load = rs.getInt(1);
        }
        rs.close();
        pstmt.close();
        return load;
    } catch (Exception e) {
        log.log(Level.SEVERE, "doIt - " + sql, e);
    }
    return 0;
}

From source file:io.github.sislivros.persistencia.UsuarioBdDao.java

@Override
public boolean salvar(Usuario usuario) {

    try {//from  w w w .  j a  v  a 2  s. c  o m

        if (getConnection() == null || getConnection().isClosed()) {
            conectar();
        }

        String sql = "INSERT INTO usuario (email, senha, apelido, data_nascimento, "
                + "cidade, estado, nome, foto_perfil, foto_capa, tipo, data_cadastro) "
                + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        PreparedStatement ps = getConnection().prepareStatement(sql);
        Date dataNascimento = null;
        if (usuario.getDataNascimento() != null) {
            dataNascimento = new Date(usuario.getDataNascimento().getTime());
        }

        ps.setString(1, usuario.getEmail());
        ps.setString(2, DigestUtils.sha1Hex(usuario.getSenha()));
        ps.setString(3, usuario.getApelido());
        ps.setDate(4, dataNascimento);
        ps.setString(5, usuario.getCidade());
        ps.setString(6, usuario.getEstado());
        ps.setString(7, usuario.getNome());
        ps.setString(8, usuario.getFotoPerfil());
        ps.setString(9, usuario.getFotoCapa());
        ps.setInt(10, usuario.getTipo().id);
        ps.setTimestamp(11, new Timestamp(System.currentTimeMillis()));
        ps.executeUpdate();

        TimeLineEvent timeLineEvent = new TimeLineEvent();
        timeLineEvent.setData(new Timestamp(System.currentTimeMillis()));
        timeLineEvent.setNome("Criou uma conta");
        timeLineEvent.setDescricao("Conta criada com sucesso !");
        timeLineEvent.setTipo(TimeLineEventType.CRIACAO_CONTA);
        timeLineEvent.setEmailUsuario(usuario.getEmail());

        TimeLineEventBdDao timeDao = new TimeLineEventBdDao();
        timeDao.salvar(timeLineEvent);

        return true;
    } catch (SQLException | URISyntaxException | IOException | ClassNotFoundException ex) {
        ex.printStackTrace();

        return false;
    } finally {
        desconectar();
    }
}

From source file:net.duckling.ddl.service.resource.dao.ResourceDAOImpl.java

@Override
public synchronized int create(final Resource res) {
    GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
    this.getJdbcTemplate().update(new PreparedStatementCreator() {
        @Override//  ww w.j  av a2 s .c o  m
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = null;
            ps = conn.prepareStatement(SQL_CREATE, PreparedStatement.RETURN_GENERATED_KEYS);
            int i = 0;
            //tid,item_type,title,creator,creator_name,create_time,last_editor,last_editor_name,last_edit_time,last_version,tags,marked_users,bid
            ps.setInt(++i, res.getTid());
            ps.setString(++i, res.getItemType());
            ps.setString(++i, res.getTitle());
            ps.setString(++i, res.getCreator());
            ps.setTimestamp(++i, new Timestamp(res.getCreateTime().getTime()));
            ps.setString(++i, res.getLastEditor());
            ps.setString(++i, res.getLastEditorName());
            ps.setTimestamp(++i, new Timestamp(res.getLastEditTime().getTime()));
            ps.setInt(++i, res.getLastVersion());
            ps.setString(++i, JsonUtil.getJSONString(res.getTagMap()));
            String fileType = (res.getFileType() != null) ? res.getFileType().toLowerCase() : res.getFileType();
            ps.setString(++i, fileType);
            ps.setObject(++i, res.getMarkedUserSet());
            ps.setInt(++i, res.getBid());
            ps.setInt(++i, res.getOrderType());
            ps.setString(++i, res.getStatus());
            ps.setLong(++i, res.getSize());
            ps.setBoolean(++i, res.isShared());
            return ps;
        }

    }, keyHolder);
    Number key = keyHolder.getKey();
    return (key == null) ? -1 : key.intValue();
}

From source file:hoot.services.db.DbUtils.java

public static void batchRecordsDirectWays(final long mapId, final List<?> records,
        final RecordBatchType recordBatchType, Connection conn, int maxRecordBatchSize) throws Exception {
    PreparedStatement ps = null;
    try {//from w w  w  . ja v a  2  s.  com
        String sql = null;
        long execResult = -1;
        //conn.setAutoCommit(false);
        int count = 0;

        switch (recordBatchType) {
        case INSERT:

            sql = "insert into current_ways_" + mapId
                    + " (id, changeset_id, \"timestamp\", visible, version, tags) "
                    + "values (?, ?, ?, ?, ?, ?)";

            ps = conn.prepareStatement(sql);
            for (Object o : records) {
                CurrentWays way = (CurrentWays) o;

                ps.setLong(1, way.getId());
                ps.setLong(2, way.getChangesetId());
                ps.setTimestamp(3, way.getTimestamp());
                ps.setBoolean(4, way.getVisible());
                ps.setLong(5, way.getVersion());

                Map<String, String> tags = (Map<String, String>) way.getTags();

                String hstoreStr = "";
                Iterator it = tags.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry pairs = (Map.Entry) it.next();
                    if (hstoreStr.length() > 0) {
                        hstoreStr += ",";
                    }
                    hstoreStr += "\"" + pairs.getKey() + "\"=>\"" + pairs.getValue() + "\"";
                }
                ps.setObject(6, hstoreStr, Types.OTHER);
                ps.addBatch();

                if (maxRecordBatchSize > -1) {
                    if (++count % maxRecordBatchSize == 0) {
                        ps.executeBatch();
                        //conn.commit();
                    }
                }

            }

            break;

        case UPDATE:

            sql = "update current_ways_" + mapId
                    + " set changeset_id=?, visible=?, \"timestamp\"=?, version=?, tags=? " + "where id=?";
            ps = conn.prepareStatement(sql);
            for (Object o : records) {
                CurrentWays way = (CurrentWays) o;

                ps.setLong(1, way.getChangesetId());
                ps.setBoolean(2, way.getVisible());
                ps.setTimestamp(3, way.getTimestamp());
                ps.setLong(4, way.getVersion());

                Map<String, String> tags = (Map<String, String>) way.getTags();

                String hstoreStr = "";
                Iterator it = tags.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry pairs = (Map.Entry) it.next();
                    if (hstoreStr.length() > 0) {
                        hstoreStr += ",";
                    }
                    hstoreStr += "\"" + pairs.getKey() + "\"=>\"" + pairs.getValue() + "\"";
                }
                ps.setObject(5, hstoreStr, Types.OTHER);

                ps.setLong(6, way.getId());

                ps.addBatch();

                if (maxRecordBatchSize > -1) {
                    if (++count % maxRecordBatchSize == 0) {
                        ps.executeBatch();
                        //conn.commit();
                    }
                }
            }

            break;

        case DELETE:

            sql = "delete from current_ways_" + mapId + " where id=?";
            ps = conn.prepareStatement(sql);
            for (Object o : records) {
                CurrentWays way = (CurrentWays) o;

                ps.setLong(1, way.getId());

                ps.addBatch();

                if (maxRecordBatchSize > -1) {
                    if (++count % maxRecordBatchSize == 0) {
                        ps.executeBatch();
                        //conn.commit();
                    }
                }

            }

            break;

        default:
            throw new Exception("");
        }

        ps.executeBatch();
        //conn.commit();
    } catch (Exception e) {
        conn.rollback();
        String msg = "Error executing batch query.";
        msg += "  " + e.getMessage();
        msg += " Cause:" + e.getCause().toString();
        throw new Exception(msg);
    } finally {
        if (ps != null) {
            ps.close();
        }
        //conn.setAutoCommit(true);
    }
}

From source file:hoot.services.db.DbUtils.java

public static void batchRecordsDirectRelations(final long mapId, final List<?> records,
        final RecordBatchType recordBatchType, Connection conn, int maxRecordBatchSize) throws Exception {
    PreparedStatement ps = null;
    try {/*from  w  w  w .  j a  v a 2 s. c  om*/
        String sql = null;
        long execResult = -1;
        //conn.setAutoCommit(false);
        int count = 0;

        switch (recordBatchType) {
        case INSERT:

            sql = "insert into current_relations_" + mapId
                    + " (id, changeset_id, \"timestamp\", visible, version, tags) "
                    + "values (?, ?, ?, ?, ?, ?)";

            ps = conn.prepareStatement(sql);
            for (Object o : records) {
                CurrentRelations rel = (CurrentRelations) o;

                ps.setLong(1, rel.getId());
                ps.setLong(2, rel.getChangesetId());
                ps.setTimestamp(3, rel.getTimestamp());
                ps.setBoolean(4, rel.getVisible());
                ps.setLong(5, rel.getVersion());

                Map<String, String> tags = (Map<String, String>) rel.getTags();

                String hstoreStr = "";
                Iterator it = tags.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry pairs = (Map.Entry) it.next();
                    if (hstoreStr.length() > 0) {
                        hstoreStr += ",";
                    }
                    hstoreStr += "\"" + pairs.getKey() + "\"=>\"" + pairs.getValue() + "\"";
                }
                ps.setObject(6, hstoreStr, Types.OTHER);
                ps.addBatch();

                if (maxRecordBatchSize > -1) {
                    if (++count % maxRecordBatchSize == 0) {
                        ps.executeBatch();
                        //conn.commit();
                    }
                }

            }

            break;

        case UPDATE:

            sql = "update current_relations_" + mapId
                    + " set changeset_id=?, visible=?, \"timestamp\"=?, version=?, tags=? " + "where id=?";
            ps = conn.prepareStatement(sql);
            for (Object o : records) {
                CurrentRelations rel = (CurrentRelations) o;

                ps.setLong(1, rel.getChangesetId());
                ps.setBoolean(2, rel.getVisible());
                ps.setTimestamp(3, rel.getTimestamp());
                ps.setLong(4, rel.getVersion());

                Map<String, String> tags = (Map<String, String>) rel.getTags();

                String hstoreStr = "";
                Iterator it = tags.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry pairs = (Map.Entry) it.next();
                    if (hstoreStr.length() > 0) {
                        hstoreStr += ",";
                    }
                    hstoreStr += "\"" + pairs.getKey() + "\"=>\"" + pairs.getValue() + "\"";
                }
                ps.setObject(5, hstoreStr, Types.OTHER);

                ps.setLong(6, rel.getId());

                ps.addBatch();

                if (maxRecordBatchSize > -1) {
                    if (++count % maxRecordBatchSize == 0) {
                        ps.executeBatch();
                        //conn.commit();
                    }
                }
            }

            break;

        case DELETE:

            sql = "delete from current_relations_" + mapId + " where id=?";
            ps = conn.prepareStatement(sql);
            for (Object o : records) {
                CurrentRelations rel = (CurrentRelations) o;

                ps.setLong(1, rel.getId());

                ps.addBatch();

                if (maxRecordBatchSize > -1) {
                    if (++count % maxRecordBatchSize == 0) {
                        ps.executeBatch();
                        //conn.commit();
                    }
                }

            }

            break;

        default:
            throw new Exception("");
        }

        ps.executeBatch();
        //conn.commit();
    } catch (Exception e) {
        conn.rollback();
        String msg = "Error executing batch query.";
        msg += "  " + e.getMessage();
        msg += " Cause:" + e.getCause().toString();
        throw new Exception(msg);
    } finally {
        if (ps != null) {
            ps.close();
        }
        //conn.setAutoCommit(true);
    }
}

From source file:com.webpagebytes.wpbsample.database.WPBDatabase.java

public Session createSession(String sessionId) throws SQLException {
    Connection connection = getConnection();
    PreparedStatement statement = null;
    try {/*from w w w .j a v a 2  s . c om*/
        Session session = new Session();
        statement = connection.prepareStatement(CREATE_SESSION_STATEMENT);
        connection.setAutoCommit(true);
        session.setId(sessionId);
        statement.setString(1, sessionId);
        session.setCreate_timestamp(new Date());
        java.sql.Timestamp sqlDate = new java.sql.Timestamp(session.getCreate_timestamp().getTime());
        statement.setTimestamp(2, sqlDate);
        HashMap<String, Object> sessionMap = new HashMap<String, Object>();
        setBinaryField(statement, 3, sessionMap);
        session.setSessionMap(sessionMap);
        statement.execute();
        return session;
    } catch (SQLException e) {
        throw e;
    } finally {
        if (statement != null) {
            statement.close();
        }
        if (connection != null) {
            connection.close();
        }
    }
}

From source file:gov.nih.nci.cabig.caaers.datamigrator.UserDataMigrator.java

/**
 * This method inserts appropriate records into site_rs_staff_roles table based on existing role_code.
 * @param map/*from ww  w.ja  va  2s  .  com*/
 * @param groups
 */
@SuppressWarnings("unchecked")
protected void insertIntoSiteResearchStaffRoles(final Map map, final List groups, final boolean onOracleDB) {
    String sql = getInsertSiteResearchStaffRoleSql(onOracleDB);
    BatchPreparedStatementSetter setter = null;
    setter = new BatchPreparedStatementSetter() {

        public int getBatchSize() {
            return groups.size();
        }

        public void setValues(PreparedStatement ps, int index) throws SQLException {

            java.sql.Timestamp startDate = (java.sql.Timestamp) map.get("start_date");
            java.sql.Timestamp endDate = (java.sql.Timestamp) map.get("end_date");

            ps.setString(1, groups.get(index).toString());

            if (onOracleDB) {
                BigDecimal siteResearchStaffId = (BigDecimal) map.get("site_research_staffs_id");
                ps.setBigDecimal(2, siteResearchStaffId);
            } else {
                int siteResearchStaffId = ((Integer) map.get("site_research_staffs_id")).intValue();
                ps.setInt(2, siteResearchStaffId);
            }
            ps.setTimestamp(3, startDate);
            ps.setTimestamp(4, endDate);
        }
    };
    getJdbcTemplate().batchUpdate(sql, setter);
}