Example usage for java.sql PreparedStatement setLong

List of usage examples for java.sql PreparedStatement setLong

Introduction

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

Prototype

void setLong(int parameterIndex, long x) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java long value.

Usage

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

@Override
public void delete(List<Penalty> list) {
    String sql = "delete from penalty where id = ?";
    Connection conn = null;//w w  w. ja v a  2s . c  o m
    try {
        conn = ConnectionFactory.getMasterConnection();
        PreparedStatement st = conn.prepareStatement(sql);
        for (Penalty p : list) {
            st.setLong(1, p.getKey());
            st.addBatch();
        }
        st.executeBatch();
    } catch (SQLException e) {
        logger.error("delete: {}", e);
    } catch (IOException e) {
        logger.error("delete: {}", e);
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
        }
    }
}

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

@Override
public Long saveRun(SavedRun savedRun) throws Exception {

    PreparedStatement ps = getConnection()
            .prepareStatement("insert into saved_runs (name, user_id, date) values (?, ?, ?)");

    ps.setString(1, savedRun.getName());
    ps.setLong(2, savedRun.getUserId());
    ps.setTimestamp(3, new Timestamp(savedRun.getDate().getTime()));

    logger.info(ps);/*w  w w. j  a va 2 s. c o  m*/
    ps.executeUpdate();

    ResultSet rs = ps.getGeneratedKeys();

    if (rs.next()) {
        return rs.getLong(1);

    }
    return null;
}

From source file:dk.netarkivet.harvester.datamodel.extendedfield.ExtendedFieldValueDBDAO.java

/**
 * Create a ExtendedFieldValue in persistent storage.
 * @param aConnection an open connection to the HarvestDatabase.
 * @param aExtendedFieldValue The ExtendedFieldValue to create in 
 *  persistent storage//w  w  w.  j av a2  s . c  o m
 * @param aCommit Should we commit this or not
 * @throws SQLException In case of Database access problems.
 */
public void create(Connection aConnection, ExtendedFieldValue aExtendedFieldValue, boolean aCommit)
        throws SQLException {
    ArgumentNotValid.checkNotNull(aExtendedFieldValue, "aExtendedFieldValue");

    if (aExtendedFieldValue.getExtendedFieldValueID() != null) {
        log.warn("The extendedFieldValueID for this extendedField Value "
                + "is already set. This should probably never happen.");
    } else {
        aExtendedFieldValue.setExtendedFieldValueID(generateNextID(aConnection));
    }

    log.debug("Creating " + aExtendedFieldValue.toString());

    PreparedStatement statement = null;
    aConnection.setAutoCommit(false);
    statement = aConnection.prepareStatement("" + "INSERT INTO extendedfieldvalue "
            + "            (extendedfieldvalue_id, " + "             extendedfield_id, "
            + "             content, " + "             instance_id) " + "VALUES      (?, " + "             ?, "
            + "             ?, " + "             ?) ");

    statement.setLong(1, aExtendedFieldValue.getExtendedFieldValueID());
    statement.setLong(2, aExtendedFieldValue.getExtendedFieldID());
    statement.setString(3, aExtendedFieldValue.getContent());
    statement.setLong(4, aExtendedFieldValue.getInstanceID());

    statement.executeUpdate();
    if (aCommit) {
        aConnection.commit();
    }
}

From source file:com.l2jfree.gameserver.model.clan.L2ClanMember.java

/**
 * Update the characters table of the database with power grade.<BR><BR>
 *//*from w w w . j av  a 2s  . co m*/
public void updatePledgeRank() {
    Connection con = null;

    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement = con
                .prepareStatement("UPDATE characters SET pledge_rank=? WHERE charId=?");
        statement.setLong(1, _pledgeRank);
        statement.setInt(2, getObjectId());
        statement.execute();
        statement.close();
    } catch (Exception e) {
        _log.warn("could not set char pledge_rank:", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:com.thinkmore.framework.orm.hibernate.SimpleHibernateDao.java

public void setParameters(PreparedStatement ps, int j, Object value) throws SQLException {
    if (value != null) {
        if (value instanceof java.lang.Integer) {
            ps.setInt(j, (Integer) value);
        } else if (value instanceof java.lang.Long) {
            ps.setLong(j, (Long) value);
        } else if (value instanceof java.util.Date) {
            ps.setTimestamp(j, new java.sql.Timestamp(((Date) value).getTime()));
        } else if (value instanceof java.sql.Date) {
            ps.setDate(j, new java.sql.Date(((Date) value).getTime()));
        } else if (value instanceof java.lang.String) {
            ps.setString(j, value.toString());
        } else if (value instanceof java.lang.Double) {
            ps.setDouble(j, (Double) value);
        } else if (value instanceof java.lang.Byte) {
            ps.setByte(j, (Byte) value);
        } else if (value instanceof java.lang.Character) {
            ps.setString(j, value.toString());
        } else if (value instanceof java.lang.Float) {
            ps.setFloat(j, (Float) value);
        } else if (value instanceof java.lang.Boolean) {
            ps.setBoolean(j, (Boolean) value);
        } else if (value instanceof java.lang.Short) {
            ps.setShort(j, (Short) value);
        } else {//from  w  w  w  . j av  a 2  s  .  c  o m
            ps.setObject(j, value);
        }
    } else {
        ps.setNull(j, Types.NULL);
    }
}

From source file:com.npstrandberg.simplemq.MessageQueueImp.java

public boolean delete(Message message) {

    // The Message instances this queue returns is
    // and instance of 'MessageWrapper', so we only
    // accept them.
    if (!(message instanceof MessageWrapper)) {
        throw new IllegalArgumentException("This instance of 'Message' is not valid.");
    }//from   ww w  .ja va  2 s .co m

    try {
        PreparedStatement ps = conn.prepareStatement("DELETE FROM message WHERE id=?");
        ps.setLong(1, message.getId());
        int i = ps.executeUpdate();
        ps.close();

        return (i > 0);
    } catch (SQLException e) {
        logger.error(e);
    }

    return false;
}

From source file:com.flexive.core.storage.genericSQL.GenericLockStorage.java

/**
 * {@inheritDoc}/*  w  w w.  j  a  v a 2s. c o m*/
 */
@Override
@SuppressWarnings({ "ThrowableInstanceNeverThrown" })
public void removeExpiredLocks(Connection con) {
    PreparedStatement ps = null;
    try {
        ps = con.prepareStatement("DELETE FROM " + TBL_LOCKS + " WHERE EXPIRES_AT<?");
        ps.setLong(1, System.currentTimeMillis());
        int count = ps.executeUpdate();
        if (count > 0)
            LOG.info("Expired " + count + " locks");
    } catch (SQLException e) {
        throw new FxDbException(e, "ex.db.sqlError", e.getMessage()).asRuntimeException();
    } finally {
        Database.closeObjects(GenericLockStorage.class, null, ps);
    }
}

From source file:com.flexive.core.storage.genericSQL.GenericTreeStorageSimple.java

/**
 * Get a node attached to the given parent at the requested position
 *
 * @param con        an open and valid connection
 * @param mode       tree mode//from  w ww . j  a v a 2 s  .co  m
 * @param parentNode parent node
 * @param position   position
 * @return FxTreeNodeInfo
 * @throws FxApplicationException on errors
 */
protected FxTreeNodeInfo getTreeNodeInfoAt(Connection con, FxTreeMode mode, FxTreeNodeInfo parentNode,
        int position) throws FxApplicationException {
    PreparedStatement ps = null;
    try {
        ps = con.prepareStatement(
                "SELECT ID FROM " + getTable(mode) + " WHERE LFT>? AND RGT<? LIMIT 1 OFFSET " + position);
        ps.setLong(1, parentNode.getLeft().longValue());
        ps.setLong(2, parentNode.getRight().longValue());
        ResultSet rs = ps.executeQuery();
        if (rs == null || !rs.next())
            throw new FxTreeException("ex.tree.nodeNotFound.position", position, parentNode.getId(),
                    mode.name());
        return getTreeNodeInfo(con, mode, rs.getLong(1));
    } catch (SQLException e) {
        throw new FxTreeException(e, "ex.db.sqlError", e.getMessage());
    } finally {
        try {
            if (ps != null)
                ps.close();
        } catch (Throwable t) {
            /*ignore*/
        }
    }
}

From source file:at.alladin.rmbt.controlServer.SettingsResource.java

private JSONArray getSyncGroupDeviceList(final ErrorList errorList, final Client client) throws SQLException {

    JSONArray ownDeviceList = null;/*from  www. ja  v  a 2  s  .  c  om*/

    final PreparedStatement st = conn.prepareStatement("SELECT DISTINCT COALESCE(adm.fullname, t.model) model"
            + " FROM test t" + " LEFT JOIN device_map adm ON adm.codename=t.model"
            + " WHERE (t.client_id IN (SELECT ? UNION SELECT uid FROM client WHERE sync_group_id = ? )) AND t.deleted = false AND t.implausible = false AND t.status = 'FINISHED' ORDER BY model ASC");

    st.setLong(1, client.getUid());
    st.setInt(2, client.getSync_group_id());

    //        System.out.println(st.toString());

    final ResultSet rs = st.executeQuery();
    if (rs != null) {

        ownDeviceList = new JSONArray();

        while (rs.next()) {
            final String model = rs.getString("model");
            if (model == null || model.isEmpty())
                ownDeviceList.put("Unknown Device");
            else
                ownDeviceList.put(model);
        }
    } else
        errorList.addError("ERROR_DB_GET_SETTING_HISTORY_DEVICES_SQL");

    rs.close();
    st.close();

    return ownDeviceList;
}

From source file:com.pactera.edg.am.metamanager.extractor.dao.helper.CreateMetadataAlterHelper.java

protected void setPs(PreparedStatement ps, AbstractMetadata metadata, String metaModelCode,
        boolean hasChildMetaModel) throws SQLException {
    // ?,0/*from   ww  w .j  a  va  2 s.  c o  m*/
    ps.setString(2, "0");

    // ??
    String namespace = metadata.getNamespace();
    ps.setString(6,
            namespace == null ? genNamespace(metadata.getParentMetadata(), metadata.getId(), hasChildMetaModel)
                    : namespace);

    // ?START_TIME
    // ?startTime
    ps.setLong(8, startTime); //metadata.getStartTime());

    // OLD_START_TIME ???OLD_START_TIME??
    ps.setNull(10, java.sql.Types.BIGINT);
}