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:org.apache.lucene.store.jdbc.index.AbstractJdbcIndexOutput.java

public void close() throws IOException {
    super.close();
    final long length = length();
    doBeforeClose();/*from ww w  . jav a2  s .  com*/
    jdbcDirectory.getJdbcTemplate().update(jdbcDirectory.getTable().sqlInsert(), new PreparedStatementSetter() {
        @Override
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setFetchSize(1);
            ps.setString(1, name);
            InputStream is = null;
            try {
                is = openInputStream();
                if (jdbcDirectory.getDialect().useInputStreamToInsertBlob()) {
                    ps.setBinaryStream(2, is, (int) length());
                } else {
                    ps.setBlob(2, new InputStreamBlob(is, length));
                }
                ps.setLong(3, length);
                ps.setBoolean(4, false);
            } catch (IOException e) {
                throw new SQLException(e);
            }
        }
    });
    doAfterClose();
}

From source file:com.amazonbird.announce.ProductMgrImpl.java

public void addProductPicture(long productId, String url) {

    Connection connection = null;
    PreparedStatement ps = null;

    ResultSet rs = null;//from ww w .  ja v a  2  s.  c  om

    try {
        connection = dbMgr.getConnection();
        ps = connection.prepareStatement(ADD_PRODUCT_PICTURE);
        ps.setLong(1, productId);
        ps.setString(2, url);
        ps.executeUpdate();

        logger.debug(DBConstants.QUERY_EXECUTION_SUCC + ps.toString());
    } catch (SQLException ex) {
        logger.error(DBConstants.QUERY_EXECUTION_FAIL + ps.toString(), ex);
    } finally {
        dbMgr.closeResources(connection, ps, rs);
    }

}

From source file:com.fluidops.iwb.wiki.WikiSQLStorageBase.java

@Override
public String getWikiContent(URI resource, WikiRevision revision) {
    PreparedStatement stat = null;
    ResultSet rs = null;//from w w w  .ja va2 s . c o  m
    try {
        Connection conn = getConnection();
        stat = conn.prepareStatement("select content from revisions where name=? and date=?");
        stat.setString(1, resource.stringValue());
        stat.setLong(2, revision.date.getTime());

        rs = stat.executeQuery();
        SQL.monitorRead();
        if (rs.next()) {
            if (com.fluidops.iwb.util.Config.getConfig().getCompressWikiInDatabase())
                return gunzip(rs.getBytes("content"));
            else
                return rs.getString("content");
        }
        return null;
    } catch (SQLException e) {
        SQL.monitorReadFailure();
        throw new RuntimeException("Retrieving wiki content failed.", e);
    } finally {
        SQL.closeQuietly(rs);
        SQL.closeQuietly(stat);
    }
}

From source file:com.amazonbird.announce.ProductMgrImpl.java

private void setProductActiveInactive(long id, boolean active) {
    Connection connection = null;
    PreparedStatement ps = null;

    try {// w  w w . ja  va2 s.c o  m
        connection = dbMgr.getConnection();
        ps = connection.prepareStatement(SET_PRODUCT_ACTIVE);
        ps.setBoolean(1, active);
        ps.setLong(2, id);
        ps.executeUpdate();
        logger.debug(DBConstants.QUERY_EXECUTION_SUCC + ps.toString());
    } catch (SQLException ex) {
        logger.error(DBConstants.QUERY_EXECUTION_FAIL + ps.toString(), ex);
    } finally {
        dbMgr.closeResources(connection, ps, null);
    }
}

From source file:dqyt.cy6.yutao.common.port.adapter.persistence.eventsourcing.mysql.MySQLJDBCEventStore.java

public List<DispatchableDomainEvent> eventsSince(long aLastReceivedEvent) {

    Connection connection = this.connection();

    ResultSet result = null;/*from  w  ww  . j  ava  2s.c o m*/

    try {
        PreparedStatement statement = connection
                .prepareStatement("SELECT event_id, event_body, event_type FROM tbl_es_event_store "
                        + "WHERE event_id > ? " + "ORDER BY event_id");

        statement.setLong(1, aLastReceivedEvent);

        result = statement.executeQuery();

        List<DispatchableDomainEvent> sequence = this.buildEventSequence(result);

        connection.commit();

        return sequence;

    } catch (Throwable t) {
        throw new EventStoreException(
                "Cannot query event for sequence since: " + aLastReceivedEvent + " because: " + t.getMessage(),
                t);
    } finally {
        if (result != null) {
            try {
                result.close();
            } catch (SQLException e) {
                // ignore
            }
        }
        try {
            connection.close();
        } catch (SQLException e) {
            // ignore
        }
    }
}

From source file:com.jagornet.dhcp.db.JdbcLeaseManager.java

/**
 * Find dhcp leases for ia.//w  ww.  ja  va2 s .c  om
 *
 * @param duid the duid
 * @param iatype the iatype
 * @param iaid the iaid
 * @return the list
 */
protected List<DhcpLease> findDhcpLeasesForIA(final byte[] duid, final byte iatype, final long iaid) {
    return getJdbcTemplate().query("select * from dhcplease" + " where duid = ?" + " and iatype = ?"
            + " and iaid = ?" + " order by ipaddress", new PreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setBytes(1, duid);
                    ps.setByte(2, iatype);
                    ps.setLong(3, iaid);
                }
            }, new DhcpLeaseRowMapper());
}

From source file:com.l2jfree.gameserver.instancemanager.games.Lottery.java

public void increasePrize(long count) {
    _prize += count;/*from  ww w . ja va2 s  .co  m*/
    Connection con = null;
    try {
        con = L2DatabaseFactory.getInstance().getConnection(con);
        PreparedStatement statement;
        statement = con.prepareStatement(UPDATE_PRICE);
        statement.setLong(1, getPrize());
        statement.setLong(2, getPrize());
        statement.setInt(3, getId());
        statement.execute();
        statement.close();
    } catch (SQLException e) {
        _log.warn("Lottery: Could not increase current lottery prize: ", e);
    } finally {
        L2DatabaseFactory.close(con);
    }
}

From source file:com.saasovation.common.port.adapter.persistence.eventsourcing.mysql.MySQLJDBCEventStore.java

@Override
public List<DispatchableDomainEvent> eventsSince(long aLastReceivedEvent) {

    Connection connection = this.connection();

    ResultSet result = null;//ww  w.  ja  v  a2  s  .  c o  m

    try {
        PreparedStatement statement = connection
                .prepareStatement("SELECT event_id, event_body, event_type FROM tbl_es_event_store "
                        + "WHERE event_id > ? " + "ORDER BY event_id");

        statement.setLong(1, aLastReceivedEvent);

        result = statement.executeQuery();

        List<DispatchableDomainEvent> sequence = this.buildEventSequence(result);

        connection.commit();

        return sequence;

    } catch (Throwable t) {
        throw new EventStoreException(
                "Cannot query event for sequence since: " + aLastReceivedEvent + " because: " + t.getMessage(),
                t);
    } finally {
        if (result != null) {
            try {
                result.close();
            } catch (SQLException e) {
                // ignore
            }
        }
        try {
            connection.close();
        } catch (SQLException e) {
            // ignore
        }
    }
}

From source file:com.jagornet.dhcp.db.JdbcIaManager.java

/**
 * Expire ia.//from  w w w.j ava  2 s.c  om
 * 
 * @param id the id
 */
protected void expireIA(final Long id) {
    getJdbcTemplate().update("update identityassoc set state=" + IdentityAssoc.EXPIRED + " where id=?"
            + " and not exists" + " (select 1 from iaaddress" + " where identityassoc_id=identityassoc.id"
            + " and validendtime>=?)", new PreparedStatementSetter() {
                @Override
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setLong(1, id);
                    java.sql.Timestamp now = new java.sql.Timestamp((new Date()).getTime());
                    ps.setTimestamp(2, now, Util.GMT_CALENDAR);
                }
            });

}

From source file:lcn.module.batch.web.guide.support.StagingItemWriter.java

/**
 * BATCH_STAGING? write/*from   w ww .  j a v  a  2s .c o  m*/
 */
public void write(final List<? extends T> items) {

    final ListIterator<? extends T> itemIterator = items.listIterator();
    getJdbcTemplate().batchUpdate("INSERT into BATCH_STAGING (ID, JOB_ID, VALUE, PROCESSED) values (?,?,?,?)",
            new BatchPreparedStatementSetter() {

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

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

                    long id = incrementer.nextLongValue();
                    long jobId = stepExecution.getJobExecution().getJobId();

                    Assert.state(itemIterator.nextIndex() == i,
                            "Item ordering must be preserved in batch sql update");

                    byte[] blob = SerializationUtils.serialize((Serializable) itemIterator.next());

                    ps.setLong(1, id);
                    ps.setLong(2, jobId);
                    ps.setBytes(3, blob);
                    ps.setString(4, NEW);
                }
            });

}