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:dao.DirectoryBlobUpdateQuery.java

public void run(Connection conn, String entryid, String directoryid, String zoom, String btitle, String caption)
        throws BaseDaoException {

    byte[] capBytes = { ' ' };
    if (!RegexStrUtil.isNull(caption)) {
        capBytes = caption.getBytes();/* ww w.  j  a v  a2  s .co  m*/
    }

    try {
        PreparedStatement stmt = conn.prepareStatement("update dirblob set caption=?, btitle='" + btitle
                + "', zoom=" + zoom + ", accessdate=CURRENT_TIMESTAMP() where entryid=" + entryid
                + " and directoryid=" + directoryid + "");
        stmt.setBytes(1, capBytes);
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing update dirblob ", e);
    }
}

From source file:ccc.cli.NewDBQueries.java

/**
 * Change migration user password.//  w  w w  .j av a2 s  .  c o  m
 *
 * @param muid UUID of the migration user;
 */
public void changeMigrationUserPw(final UUID muid) {

    final UUID pwId = UUID.randomUUID();
    final byte[] hash = Encryption.hash("" + new Date().getTime(), pwId.toString());

    PreparedStatement ps = null;

    try {
        // update password
        ps = _connection.prepareStatement("UPDATE users SET hash=?, vn=1 WHERE user_id = ?");
        ps.setBytes(1, hash);
        ps.setString(2, muid.toString());
        ps.executeUpdate();
        _connection.commit();

    } catch (final SQLException e) {
        throw new RuntimeException(e);
    } finally {
        DbUtils.closeQuietly(ps);
    }
}

From source file:org.pentaho.platform.repository.hibernate.usertypes.BlobtoByteArrayUserType.java

public void nullSafeSet(final PreparedStatement arg0, final Object arg1, final int arg2)
        throws HibernateException, SQLException {

    if (arg1 != null) {
        try {/* w  ww  .j a  v  a  2 s.c  o  m*/
            arg0.setBytes(arg2, (byte[]) arg1);
        } catch (SerializationException ex) {
            BlobtoByteArrayUserType.log
                    .error(Messages.getInstance().getErrorString("BLOBUTYPE.ERROR_0001_SETTING_BLOB"), ex); //$NON-NLS-1$
            throw new HibernateException(
                    Messages.getInstance().getErrorString("BLOBUTYPE.ERROR_0001_SETTING_BLOB"), ex); //$NON-NLS-1$
        }
    } else {
        arg0.setNull(arg2, sqlTypes()[0]);
    }
}

From source file:dao.DirWebsiteAddQuery.java

/**
 * This method is not called by spring./*from w  w  w  . j  ava 2 s  .  c  o m*/
 *
 * @param conn the connection passed to this.
 * @param url the url name
 * @param title the title
 * @param categoryid the category id
 * @param ownerid the owner id 
 * @exception BaseDaoException
 */
public void run(Connection conn, String url, String title, String categoryid, String ownerid)
        throws BaseDaoException {

    byte[] myUrl = { ' ' };
    if (!RegexStrUtil.isNull(url)) {
        myUrl = url.getBytes();
    }

    byte[] myTitle = { ' ' };
    if (!RegexStrUtil.isNull(title)) {
        myTitle = title.getBytes();
    }

    PreparedStatement query = null;
    String stmt = null;

    try {
        stmt = "insert into dirwebsites values (0, " + categoryid + ", " + ownerid
                + ", CURRENT_TIMESTAMP(), ?, ?, 0)";
        query = conn.prepareStatement(stmt);
        query.setBytes(1, myUrl);
        query.setBytes(2, myTitle);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing directoryurladd, query = " + stmt, e);
    }
}

From source file:dao.CollHitsQuery.java

/**
 * This method is not called by spring.//from w ww  .ja v a 2 s  .com
 *
 * @param conn the connection passed to this.
 * @param collabrumid the collabrumid 
 * @param visitorid the visitorid 
 * @param referer the referer 
 * @param ipaddress the ipaddress 
 * @exception BaseDaoException
 */

public void run(Connection conn, String collabrumid, String visitorid, String referer, String ipaddress)
        throws BaseDaoException {
    byte[] byteReferer = { ' ' };
    if (!RegexStrUtil.isNull(referer)) {
        byteReferer = referer.getBytes();
    }

    PreparedStatement query = null;
    String stmt = null;
    try {
        stmt = "insert delayed into colltraffic values(" + collabrumid + ", " + visitorid + ", ?, '" + ipaddress
                + "', CURRENT_TIMESTAMP())";
        query = conn.prepareStatement(stmt);
        query.setBytes(1, byteReferer);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured, executing directory updating hits, query = " + stmt, e);
    }
}

From source file:dao.ColTopicAddQuery.java

/**
 * This method is executed by ColTopicDao.
 * @param conn  - the connection/*from  w ww .  ja v a 2s .  co m*/
 * @param collabrumid - the collabrum id 
 * @param message - the message 
 * @param topic - the topic 
 * @param ownerid - the owner id
 * @throws BaseDaoException
 **/
public void run(Connection conn, String collabrumid, String message, String topic, String ownerid, String title)
        throws BaseDaoException {

    byte[] msg = { ' ' };
    if (!RegexStrUtil.isNull(message)) {
        msg = message.getBytes();
    }

    byte[] mytopic = { ' ' };
    if (!RegexStrUtil.isNull(topic)) {
        mytopic = topic.getBytes();
    }

    byte[] mytitle = { ' ' };
    if (!RegexStrUtil.isNull(title)) {
        mytitle = title.getBytes();
    }

    PreparedStatement query = null;

    try {
        String stmt = "insert into colltopics values(" + 0 + ", " + collabrumid + ", " + ownerid
                + ", CURRENT_TIMESTAMP(), ?, ?, 0, 0, 0, ?)";

        query = conn.prepareStatement(stmt);
        query.setBytes(1, mytopic);
        query.setBytes(2, msg);
        query.setBytes(3, mytitle);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing colltopics addquery", e);
    }
}

From source file:dao.PblogAddRecentVisitQuery.java

/**
 * This method is executed by PblogMessageDao
 * It is used to insert an entry (delayed) into pblogrecentvisits table
 * @param conn  - the connection/*from   w w  w  .  j  ava 2  s  .  c om*/
 * @param fname  - the first name of the blogger
 * @param blogUrl  - the blog url
 * @param photoUrl  - the photo url
 * @param message - the message 
 * @throws BaseDaoException
 **/
public void run(Connection conn, String blogUrl, String photoUrl, String message, String fname,
        String userLogin) throws BaseDaoException {

    byte[] msg = { ' ' };
    if (!RegexStrUtil.isNull(message)) {
        int length = 20;
        if (message.length() < 20) {
            length = message.length();
        }
        msg = message.substring(0, length).getBytes();
    }

    PreparedStatement query = null;
    String stmt = "insert delayed into pblogrecentvisits values(CURRENT_TIMESTAMP(), '" + fname + "', '"
            + blogUrl + "', '" + photoUrl + "', ?, '" + userLogin + "')";
    try {
        query = conn.prepareStatement(stmt);
        query.setBytes(1, msg);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing pblogrecentvisit addquery, stmt = " + stmt,
                e);
    }
}

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

public List<IaAddress> findAllByRange(final InetAddress startAddr, final InetAddress endAddr) {
    return getJdbcTemplate().query(
            "select * from iaaddress where ipaddress >= ? and ipaddress <= ? order by ipaddress",
            new PreparedStatementSetter() {
                @Override/*from   w  w w.ja v a  2s .  c o  m*/
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setBytes(1, startAddr.getAddress());
                    ps.setBytes(2, endAddr.getAddress());
                }
            }, new IaAddrRowMapper());
}

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

public List<IaPrefix> findAllByRange(final InetAddress startAddr, final InetAddress endAddr) {
    return getJdbcTemplate().query("select * from iaprefix" + " where prefixaddress >= ? and prefixaddress <= ?"
            + " order by prefixaddress", new PreparedStatementSetter() {
                @Override/*from  w w  w  . j a  v a 2 s .c  o m*/
                public void setValues(PreparedStatement ps) throws SQLException {
                    ps.setBytes(1, startAddr.getAddress());
                    ps.setBytes(2, endAddr.getAddress());
                }
            }, new IaPrefixRowMapper());
}

From source file:org.snaker.engine.access.jdbc.JdbcAccess.java

/**
 * JDBC?BLOB/*from  w  ww . j av  a2  s .  c  o  m*/
 */
public void saveProcess(Process process) {
    super.saveProcess(process);
    if (process.getBytes() != null) {
        Connection conn = null;
        PreparedStatement pstmt = null;
        try {
            conn = getConnection();
            pstmt = conn.prepareStatement(PROCESS_UPDATE_BLOB);
            pstmt.setBytes(1, process.getBytes());
            pstmt.setString(2, process.getId());
            pstmt.execute();
        } catch (Exception e) {
            throw new SnakerException(e.getMessage(), e.getCause());
        } finally {
            try {
                JdbcHelper.close(pstmt);
            } catch (SQLException e) {
                throw new SnakerException(e.getMessage(), e.getCause());
            }
        }
    }
}