Example usage for java.sql PreparedStatement setBytes

List of usage examples for java.sql PreparedStatement setBytes

Introduction

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

Prototype

void setBytes(int parameterIndex, byte x[]) throws SQLException;

Source Link

Document

Sets the designated parameter to the given Java array of bytes.

Usage

From source file:lineage2.gameserver.cache.CrestCache.java

/**
 * Method savePledgeCrest.//from www.  ja  v  a2s . c  o m
 * @param pledgeId int
 * @param crest byte[]
 * @return int
 */
public int savePledgeCrest(int pledgeId, byte[] crest) {
    int crestId = getCrestId(pledgeId, crest);
    writeLock.lock();
    try {
        _pledgeCrestId.put(pledgeId, crestId);
        _pledgeCrest.put(crestId, crest);
    } finally {
        writeLock.unlock();
    }
    Connection con = null;
    PreparedStatement statement = null;
    try {
        con = DatabaseFactory.getInstance().getConnection();
        statement = con.prepareStatement("UPDATE clan_data SET crest=? WHERE clan_id=?");
        statement.setBytes(1, crest);
        statement.setInt(2, pledgeId);
        statement.execute();
    } catch (Exception e) {
        _log.error("", e);
    } finally {
        DbUtils.closeQuietly(con, statement);
    }
    return crestId;
}

From source file:lineage2.gameserver.cache.CrestCache.java

/**
 * Method saveAllyCrest./*  www .j a v a  2  s . c  o m*/
 * @param pledgeId int
 * @param crest byte[]
 * @return int
 */
public int saveAllyCrest(int pledgeId, byte[] crest) {
    int crestId = getCrestId(pledgeId, crest);
    writeLock.lock();
    try {
        _allyCrestId.put(pledgeId, crestId);
        _allyCrest.put(crestId, crest);
    } finally {
        writeLock.unlock();
    }
    Connection con = null;
    PreparedStatement statement = null;
    try {
        con = DatabaseFactory.getInstance().getConnection();
        statement = con.prepareStatement("UPDATE ally_data SET crest=? WHERE ally_id=?");
        statement.setBytes(1, crest);
        statement.setInt(2, pledgeId);
        statement.execute();
    } catch (Exception e) {
        _log.error("", e);
    } finally {
        DbUtils.closeQuietly(con, statement);
    }
    return crestId;
}

From source file:lineage2.gameserver.cache.CrestCache.java

/**
 * Method savePledgeCrestLarge./*w w  w.j a  v a 2  s  . c  o  m*/
 * @param pledgeId int
 * @param crest byte[]
 * @return int
 */
public int savePledgeCrestLarge(int pledgeId, byte[] crest) {
    int crestId = getCrestId(pledgeId, crest);
    writeLock.lock();
    try {
        _pledgeCrestLargeId.put(pledgeId, crestId);
        get_pledgeCrestLarge().put(crestId, crest);
    } finally {
        writeLock.unlock();
    }
    Connection con = null;
    PreparedStatement statement = null;
    try {
        con = DatabaseFactory.getInstance().getConnection();
        statement = con.prepareStatement("UPDATE clan_data SET largecrest=? WHERE clan_id=?");
        statement.setBytes(1, crest);
        statement.setInt(2, pledgeId);
        statement.execute();
    } catch (Exception e) {
        _log.error("", e);
    } finally {
        DbUtils.closeQuietly(con, statement);
    }
    return crestId;
}

From source file:eu.europa.esig.dss.client.crl.JdbcCacheCRLSource.java

/**
 * Update the cache with the CRL/*  ww  w . j  a v a 2s .co  m*/
 *
 * @param key     the key
 * @param encoded the encoded CRL
 * @throws java.sql.SQLException
 */
private void updateCrlInDb(String key, byte[] encoded) throws SQLException {

    Connection c = null;
    PreparedStatement s = null;
    ResultSet rs = null;
    try {
        c = getDataSource().getConnection();
        s = c.prepareStatement(sqlFindUpdate);
        s.setBytes(1, encoded);
        s.setString(2, key);
        s.executeUpdate();
    } finally {
        closeQuietly(c, s, rs);
    }

}

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

public void create(final IaPrefix iaPrefix) {
    /**//  w w  w.  j  a v a2s. c om
     * Note: see https://issues.apache.org/jira/browse/DERBY-3609
     * "Formally, Derby does not support getGeneratedKeys since 
     * DatabaseMetaData.supportsGetGeneratedKeys() returns false. 
     * However, Statement.getGeneratedKeys() is partially implemented,
     * ... since it will only return a meaningful result when an single 
     * row insert is done with INSERT...VALUES"
     * 
     * Spring has thus provided a workaround as described here:
     * http://jira.springframework.org/browse/SPR-5306
     */
    GeneratedKeyHolder newKey = new GeneratedKeyHolder();
    getJdbcTemplate().update(new PreparedStatementCreator() {
        @Override
        public PreparedStatement createPreparedStatement(Connection conn) throws SQLException {
            PreparedStatement ps = conn.prepareStatement(
                    "insert into iaprefix" + " (prefixaddress, prefixlength, starttime, preferredendtime,"
                            + " validendtime, state, identityassoc_id)" + " values (?, ?, ?, ?, ?, ?, ?)",
                    PreparedStatement.RETURN_GENERATED_KEYS);
            ps.setBytes(1, iaPrefix.getIpAddress().getAddress());
            ps.setInt(2, iaPrefix.getPrefixLength());
            java.sql.Timestamp sts = new java.sql.Timestamp(iaPrefix.getStartTime().getTime());
            ps.setTimestamp(3, sts, Util.GMT_CALENDAR);
            java.sql.Timestamp pts = new java.sql.Timestamp(iaPrefix.getPreferredEndTime().getTime());
            ps.setTimestamp(4, pts, Util.GMT_CALENDAR);
            java.sql.Timestamp vts = new java.sql.Timestamp(iaPrefix.getValidEndTime().getTime());
            ps.setTimestamp(5, vts, Util.GMT_CALENDAR);
            ps.setByte(6, iaPrefix.getState());
            ps.setLong(7, iaPrefix.getIdentityAssocId());
            return ps;
        }
    }, newKey);
    Number newId = newKey.getKey();
    if (newId != null) {
        iaPrefix.setId(newId.longValue());
    }
}

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

@Override
public long insertMutatiesFile(final java.util.Date dateFrom, final java.util.Date dateTo, final byte[] content)
        throws DAOException {
    try {/*from   w ww . jav a  2  s .  c om*/
        KeyHolder keyHolder = new GeneratedKeyHolder();
        jdbcTemplate.update(new PreparedStatementCreator() {
            @Override
            public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
                PreparedStatement ps = connection.prepareStatement("insert into bag_mutaties_file (" + " id,"
                        + " date_from," + " date_to," + " content"
                        + ") values ((select nvl(max(id),0) + 1 from bag_mutaties_file),trunc(?),trunc(?),?)",
                        new int[] { 1 });
                ps.setDate(1, new Date(dateFrom.getTime()));
                ps.setDate(2, new Date(dateTo.getTime()));
                ps.setBytes(3, content);
                return ps;
            }
        }, keyHolder);
        return keyHolder.getKey().longValue();
    } catch (DataAccessException e) {
        throw new DAOException(e);
    }
}

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

/**
 * BATCH_STAGING? write//from  ww  w .  j ava 2  s .  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);
                }
            });

}

From source file:eu.europa.esig.dss.client.crl.JdbcCacheCRLSource.java

/**
 * Insert a new CRL into the cache//from  w w  w . j  av  a  2 s  .  co m
 *
 * @param key     the key
 * @param encoded the encoded CRL
 * @throws java.sql.SQLException
 */
private void insertCrlInDb(String key, byte[] encoded) throws SQLException {

    Connection c = null;
    PreparedStatement s = null;
    ResultSet rs = null;
    try {
        c = getDataSource().getConnection();
        s = c.prepareStatement(sqlFindInsert);
        s.setString(1, key);
        s.setBytes(2, encoded);
        s.executeUpdate();
    } finally {
        closeQuietly(c, s, rs);
    }
}

From source file:org.panbox.core.keymgmt.JDBCHelperNonRevokeable.java

private void storeSignature(Connection con, byte[] signature) throws SQLException, PersistanceException {
    PreparedStatement insert = con.prepareStatement(INSERT_SIGNATURE);
    insert.setBytes(1, signature);
    insert.executeUpdate();/*from  ww w  .  j av a 2 s  .  c om*/
    if (insert != null) {
        try {
            insert.close();
        } catch (Exception e) {
            logger.warn("Could not close Statement", e);
        }
    }
}

From source file:org.sakaiproject.metaobj.shared.model.impl.HibernateSchemaNode.java

public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
    if (value == null) {
        st.setNull(index, Types.VARBINARY);
    } else {// w w  w. j  av a  2  s  .c o  m
        SchemaNode schemaNode = (SchemaNode) value;
        Document doc = schemaNode.getSchemaElement().getDocument();

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        XMLOutputter xmlOutputter = new XMLOutputter();
        try {
            xmlOutputter.output(doc, out);
        } catch (IOException e) {
            throw new HibernateException(e);
        }
        st.setBytes(index, out.toByteArray());
    }
}