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:fr.aliacom.obm.common.contact.ContactDaoJdbcImpl.java

@Override
public Set<Folder> findUpdatedFolders(Date timestamp, AccessToken at) throws SQLException {
    String q = "SELECT a.id, a.name, userobm_id, userobm_lastname, userobm_firstname, userobm_login, domain.domain_name"
            + " FROM AddressBook a "
            + " INNER JOIN SyncedAddressbook as s ON (addressbook_id=id AND user_id=?) "
            + " INNER JOIN UserObm ON (owner=userobm_id) "
            + " INNER JOIN Domain as domain ON (userobm_domain_id=domain.domain_id) "
            + "WHERE (a.syncable OR a.name=?) AND "
            + "(a.timeupdate >= ? OR a.timecreate >= ? OR s.timestamp >= ?)";

    int idx = 1;/*w ww .j  av a 2  s .c  o m*/

    Set<Folder> folders = new HashSet<Folder>();
    Connection con = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        con = obmHelper.getConnection();
        ps = con.prepareStatement(q);
        int userId = at.getObmId();
        ps.setInt(idx++, userId);
        ps.setString(idx++, contactConfiguration.getDefaultAddressBookName());
        ps.setTimestamp(idx++, new Timestamp(timestamp.getTime()));
        ps.setTimestamp(idx++, new Timestamp(timestamp.getTime()));
        ps.setTimestamp(idx++, new Timestamp(timestamp.getTime()));
        rs = ps.executeQuery();
        while (rs.next()) {
            Folder f = buildFolder(at, rs);
            folders.add(f);
        }

    } finally {
        obmHelper.cleanup(con, ps, rs);
    }

    logger.info("returning " + folders.size() + " folder(s) updated");

    return folders;
}

From source file:com.tremolosecurity.provisioning.core.providers.BasicDB.java

private PreparedStatement updateField(User user, Connection con, StringBuffer b, String attrName, String userID,
        int userIDnum) throws SQLException {
    b.setLength(0);/* w  w  w  . j  a  v a 2 s .com*/
    b.append("UPDATE ").append(this.userTable).append(" SET ");
    this.getFieldName(attrName, b).append("=? WHERE ");
    this.getFieldName(this.userPrimaryKey, b).append("=?");
    PreparedStatement ps = con.prepareStatement(b.toString());
    ps.setString(1, user.getAttribs().get(attrName).getValues().get(0));
    if (userIDnum != -1) {
        ps.setInt(2, userIDnum);
    } else {

        Attribute.DataType tat = user.getAttribs().get(attrName).getDataType();
        switch (tat) {
        case string:
            ps.setString(2, userID);
            break;
        case intNum:
            ps.setInt(2, Integer.parseInt(userID));
            break;
        case longNum:
            ps.setLong(2, Long.parseLong(userID));
            break;

        case date:
            ps.setDate(2, new Date(ISODateTimeFormat.date().parseDateTime(userID).getMillis()));
            break;
        case timeStamp:
            ps.setTimestamp(2, new Timestamp(ISODateTimeFormat.dateTime().parseDateTime(userID).getMillis()));
            break;
        }

        ps.setString(2, userID);
    }
    ps.executeUpdate();
    return ps;
}

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

@Override
public void delete(final Pand pand) {
    try {/*from   w  w w . j  a va 2 s  .  com*/
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("delete from bag_pand"
                        + " where bag_pand_id = ?" + " and aanduiding_record_correctie = ?"
                        + " and begindatum_tijdvak_geldigheid = ?" + " and einddatum_tijdvak_geldigheid = ?");
                ps.setLong(1, pand.getIdentificatie());
                ps.setLong(2, pand.getAanduidingRecordCorrectie());
                ps.setTimestamp(3, new Timestamp(pand.getBegindatumTijdvakGeldigheid().getTime()));
                if (pand.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(4, Types.TIMESTAMP);
                else
                    ps.setTimestamp(4, new Timestamp(pand.getEinddatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

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

@Override
public void delete(final Ligplaats ligplaats) {
    try {//  w  w w  .  j  a v a 2  s .  c  o  m
        deleteNevenadressen(TypeAdresseerbaarObject.LIGPLAATS, ligplaats);
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("delete from bag_ligplaats"
                        + " where bag_ligplaats_id = ?" + " and aanduiding_record_correctie = ?"
                        + " and begindatum_tijdvak_geldigheid = ?" + " and einddatum_tijdvak_geldigheid = ?");
                ps.setLong(1, ligplaats.getIdentificatie());
                ps.setLong(2, ligplaats.getAanduidingRecordCorrectie());
                ps.setTimestamp(3, new Timestamp(ligplaats.getBegindatumTijdvakGeldigheid().getTime()));
                if (ligplaats.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(4, Types.TIMESTAMP);
                else
                    ps.setTimestamp(4, new Timestamp(ligplaats.getEinddatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

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

@Override
public void delete(final Woonplaats woonplaats) {
    try {/*from  www.  jav a  2  s  .c om*/
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("delete from bag_woonplaats"
                        + " where bag_woonplaats_id = ?" + " and aanduiding_record_correctie = ?"
                        + " and begindatum_tijdvak_geldigheid = ?" + " and einddatum_tijdvak_geldigheid = ?");
                ps.setLong(1, woonplaats.getIdentificatie());
                ps.setLong(2, woonplaats.getAanduidingRecordCorrectie());
                ps.setTimestamp(3, new Timestamp(woonplaats.getBegindatumTijdvakGeldigheid().getTime()));
                if (woonplaats.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(4, Types.TIMESTAMP);
                else
                    ps.setTimestamp(4, new Timestamp(woonplaats.getEinddatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

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

@Override
public void delete(final Standplaats standplaats) {
    try {/*from  w  ww  . j  a va 2  s .  c  o m*/
        deleteNevenadressen(TypeAdresseerbaarObject.STANDPLAATS, standplaats);
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("delete from bag_standplaats"
                        + " where bag_standplaats_id = ?" + " and aanduiding_record_correctie = ?"
                        + " and begindatum_tijdvak_geldigheid = ?" + " and einddatum_tijdvak_geldigheid = ?");
                ps.setLong(1, standplaats.getIdentificatie());
                ps.setLong(2, standplaats.getAanduidingRecordCorrectie());
                ps.setTimestamp(3, new Timestamp(standplaats.getBegindatumTijdvakGeldigheid().getTime()));
                if (standplaats.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(4, Types.TIMESTAMP);
                else
                    ps.setTimestamp(4, new Timestamp(standplaats.getEinddatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

From source file:com.draagon.meta.manager.db.ObjectManagerDB.java

protected PreparedStatement getPreparedStatement(Connection c, String query, Collection<?> args)
        throws MetaException, SQLException {
    String sql = query; // (String) mOQLCache.get( query );

    // If it's not in the cache, then parse it and put it there
    //if ( sql == null )
    //{//from w w w.j  a v a 2s  . c om
    //Map<String,MetaClass> m = getMetaClassMap( query );

    //if ( m.size() > 0 ) {
    //   sql = convertToSQL( query, m );
    //}
    //else sql = query;

    //mOQLCache.put( query, sql );
    //}

    PreparedStatement s = c.prepareStatement(sql);

    if (args != null) {
        int i = 1;
        for (Object o : args) {
            if (o instanceof Boolean) {
                s.setBoolean(i, (Boolean) o);
            } else if (o instanceof Byte) {
                s.setByte(i, (Byte) o);
            } else if (o instanceof Short) {
                s.setShort(i, (Short) o);
            } else if (o instanceof Integer) {
                s.setInt(i, (Integer) o);
            } else if (o instanceof Long) {
                s.setLong(i, (Long) o);
            } else if (o instanceof Float) {
                s.setFloat(i, (Float) o);
            } else if (o instanceof Double) {
                s.setDouble(i, (Double) o);
            } else if (o instanceof Date) {
                s.setTimestamp(i, new Timestamp(((Date) o).getTime()));
            } else if (o == null) {
                s.setString(i, null);
            } else {
                s.setString(i, o.toString());
            }

            // Increment the i
            i++;
        }
    }

    return s;
}

From source file:mysql5.MySQL5PlayerDAO.java

/**
 * {@inheritDoc}//from   ww w  .j  ava  2 s  .c o m
 */
@Override
public void storePlayer(final Player player) {
    Connection con = null;
    try {
        con = DatabaseFactory.getConnection();
        PreparedStatement stmt = con.prepareStatement(
                "UPDATE players SET name=?, exp=?, recoverexp=?, x=?, y=?, z=?, heading=?, world_id=?, gender=?, race=?, player_class=?, last_online=?, quest_expands=?, npc_expands=?, advanced_stigma_slot_size=?, warehouse_size=?, note=?, title_id=?, bonus_title_id=?, dp=?, soul_sickness=?, mailbox_letters=?, reposte_energy=?, event_exp=?, bg_points=?, mentor_flag_time=?, initial_gamestats=?, world_owner=?, fatigue=?, fatigueRecover=?, fatigueReset=?, stamps=?, rewarded_pass=?, last_stamp=?, joinRequestLegionId=?, joinRequestState=? WHERE id=?");

        log.debug("[DAO: MySQL5PlayerDAO] storing player " + player.getObjectId() + " " + player.getName());
        PlayerCommonData pcd = player.getCommonData();
        stmt.setString(1, player.getName());
        stmt.setLong(2, pcd.getExp());
        stmt.setLong(3, pcd.getExpRecoverable());
        stmt.setFloat(4, player.getX());
        stmt.setFloat(5, player.getY());
        stmt.setFloat(6, player.getZ());
        stmt.setInt(7, player.getHeading());
        stmt.setInt(8, player.getWorldId());
        stmt.setString(9, player.getGender().toString());
        stmt.setString(10, player.getRace().toString());
        stmt.setString(11, pcd.getPlayerClass().toString());
        stmt.setTimestamp(12, pcd.getLastOnline());
        stmt.setInt(13, player.getQuestExpands());
        stmt.setInt(14, player.getNpcExpands());
        stmt.setInt(15, pcd.getAdvancedStigmaSlotSize());
        stmt.setInt(16, player.getWarehouseSize());
        stmt.setString(17, pcd.getNote());
        stmt.setInt(18, pcd.getTitleId());
        stmt.setInt(19, pcd.getBonusTitleId());
        stmt.setInt(20, pcd.getDp());
        stmt.setInt(21, pcd.getDeathCount());
        Mailbox mailBox = player.getMailbox();
        int mails = mailBox != null ? mailBox.size() : pcd.getMailboxLetters();
        stmt.setInt(22, mails);
        stmt.setLong(23, pcd.getCurrentReposteEnergy());
        stmt.setLong(24, pcd.getCurrentEventExp());
        stmt.setInt(25, player.getCommonData().getBattleGroundPoints());
        stmt.setInt(26, pcd.getMentorFlagTime());
        stmt.setInt(27, pcd.isInitialGameStats());
        if (player.getPosition().getWorldMapInstance() == null) {
            log.error("Error saving player: " + player.getObjectId() + " " + player.getName()
                    + ", world map instance is null. Setting world owner to 0. Position: " + player.getWorldId()
                    + " " + player.getX() + " " + player.getY() + " " + player.getZ());
            stmt.setInt(28, 0);
        } else {
            stmt.setInt(28, player.getPosition().getWorldMapInstance().getOwnerId());
        }
        stmt.setInt(29, pcd.getFatigue());
        stmt.setInt(30, pcd.getFatigueRecover());
        stmt.setInt(31, pcd.getFatigueReset());
        stmt.setInt(32, pcd.getPassportStamps());
        stmt.setInt(33, pcd.getPassportReward());
        stmt.setTimestamp(34, pcd.getLastStamp());
        stmt.setInt(35, pcd.getJoinRequestLegionId());
        stmt.setString(36, pcd.getJoinRequestState().name());
        stmt.setInt(37, player.getObjectId());
        stmt.execute();
        stmt.close();
    } catch (Exception e) {
        log.error("Error saving player: " + player.getObjectId() + " " + player.getName(), e);
    } finally {
        DatabaseFactory.close(con);
    }
    if (CacheConfig.CACHE_COMMONDATA) {
        PlayerCommonData cached = playerCommonData.get(player.getObjectId());
        if (cached != null) {
            playerCommonData.putEntry(player.getCommonData().getPlayerObjId(), player.getCommonData());
            playerCommonDataByName.putEntry(player.getName().toLowerCase(), player.getCommonData());
        }
    }
}

From source file:nl.nn.adapterframework.jdbc.JdbcTransactionalStorage.java

/**
 * Retrieves the value of the primary key for the record just inserted. 
 *//*from   ww w .ja v  a  2s. c  om*/
protected String retrieveKey(Connection conn, String messageId, String correlationId,
        Timestamp receivedDateTime) throws SQLException, SenderException {
    PreparedStatement stmt = null;

    try {
        if (log.isDebugEnabled())
            log.debug("preparing key retrieval statement [" + selectKeyQuery + "]");
        stmt = conn.prepareStatement(selectKeyQuery);
        if (!selectKeyQueryIsDbmsSupported) {
            int paramPos = applyStandardParameters(stmt, true, false);
            stmt.setString(paramPos++, messageId);
            stmt.setString(paramPos++, correlationId);
            stmt.setTimestamp(paramPos++, receivedDateTime);
        }

        ResultSet rs = null;
        try {
            rs = stmt.executeQuery();
            if (!rs.next()) {
                throw new SenderException("could not retrieve key for stored message [" + messageId + "]");
            }
            return rs.getString(1);
        } finally {
            if (rs != null) {
                rs.close();
            }
        }
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}

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

@Override
public void delete(final OpenbareRuimte openbareRuimte) {
    try {//from  ww w .  j  av a2 s .co m
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("delete from bag_openbare_ruimte"
                        + " where bag_openbare_ruimte_id = ?" + " and aanduiding_record_correctie = ?"
                        + " and begindatum_tijdvak_geldigheid = ?" + " and einddatum_tijdvak_geldigheid = ?");
                ps.setLong(1, openbareRuimte.getIdentificatie());
                ps.setLong(2, openbareRuimte.getAanduidingRecordCorrectie());
                ps.setTimestamp(3, new Timestamp(openbareRuimte.getBegindatumTijdvakGeldigheid().getTime()));
                if (openbareRuimte.getEinddatumTijdvakGeldigheid() == null)
                    ps.setNull(4, Types.TIMESTAMP);
                else
                    ps.setTimestamp(4, new Timestamp(openbareRuimte.getEinddatumTijdvakGeldigheid().getTime()));
                return ps;
            }
        });
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}