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.DirTrafficAddQuery.java

/**
 * This method is not called by spring.//from w  ww .  j ava 2 s.  co m
 * This method adds visitor information for a directory
 * @param conn the connection passed to this.
 * @param dirid the directory id
 * @param visitorid the visitor id for this directory
 * @param referer the referer that sent this visitor to the directory
 * @param ipaddress the ipaddress of this visitor
 * @exception BaseDaoException
 */
public void run(Connection conn, String dirid, String visitorid, String referer, String ipaddress)
        throws BaseDaoException {

    byte[] byteReferer = { ' ' };
    if (!RegexStrUtil.isNull(referer)) {
        byteReferer = referer.getBytes();
    }
    String stmt = "insert delayed into dirtraffic values (0, " + dirid + ", " + visitorid + ", ?, '" + ipaddress
            + "', CURRENT_TIMESTAMP())";
    try {
        PreparedStatement query = conn.prepareStatement(stmt);
        query.setBytes(1, byteReferer);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing DirTrafficAddQuery(), " + stmt, e);
    }
}

From source file:dao.CarryonTagsAddQuery.java

/**
 * This method is not called by spring.//  w w w . j  av  a 2s.com
 * This method adds userstags to the photos
 * @param conn the connection passed to this.
 * @param ownerid the owner id
 * @param usertags usertags for photos
 * @param title title for photos
 * @exception BaseDaoException
 */
public void run(Connection conn, String ownerid, String usertags, String title, String entryId, int category)
        throws BaseDaoException {

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

    String stmt = "insert into carryontag values (" + ownerid + ", " + entryId + ", '" + usertags + "', ?, "
            + category + ")";
    try {
        PreparedStatement query = conn.prepareStatement(stmt);
        query.setBytes(1, caption);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing inserting in carryontag" + stmt, e);
    }
}

From source file:dao.PblogTopicAddQuery.java

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

    /* Long myownerid = new Long(ownerid); */
    byte[] msg = { ' ' };
    if (!RegexStrUtil.isNull(message)) {
        msg = message.getBytes();
    }

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

    String stmt = "insert into pblogtopics values(0, " + myownerid
            + ", CURRENT_TIMESTAMP(), ?, ?, 0, 0, CURRENT_TIMESTAMP())";
    try {
        // String stmt = "insert into pblogtopics values(tid="+0+", pblogid="+myownerid+", entrydate=CURRENT_TIMESTAMP(), createdate=CURRENT_TIMESTAMP(), topic=?, message=?, freeze=0, screen=0)";
        PreparedStatement query = null;
        query = conn.prepareStatement(stmt);
        query.setBytes(1, mytopic);
        query.setBytes(2, msg);
        query.executeUpdate();
    } catch (Exception e) {
        logger.warn("Error occured while executing pblogtopics addquery" + stmt, e);
        throw new BaseDaoException("Error occured while executing pblogtopics addquery" + stmt, e);
    }
}

From source file:org.melati.poem.BinaryPoemType.java

protected void _setRaw(PreparedStatement ps, int col, Object string) throws SQLException {
    ps.setBytes(col, (byte[]) string);
}

From source file:dao.PersonalinfoUpdateQuery.java

public void run(Connection conn, String dob, String title, String ihave, String iwant, String industry,
        String company, String pwebsite, String cwebsite, String blogsite, String education, String city,
        String state, String country, String desc, String interests, String zipcode, int gender,
        String nickname, String designation, String bcity, String bstate, String bcountry, String bzipcode,
        String hphone, String cphone, String bphone, String yim, String aim, String msn, String icq,
        String loginid, String photoLabel, String docLabel, String street, String bstreet, String zone)
        throws BaseDaoException {

    byte[] mydesc = { ' ' };
    if (!RegexStrUtil.isNull(desc)) {
        mydesc = desc.getBytes();//from   www.j  a va  2s  . c o  m
    }

    String stmt = "update usertab set dob='" + dob + "', title='" + title + "', ihave='" + ihave + "', iwant='"
            + iwant + "', industry='" + industry + "', company='" + company + "', pwebsite='" + pwebsite
            + "', cwebsite='" + cwebsite + "', blogsite='" + blogsite + "', education='" + education
            + "', city='" + city + "', state='" + state + "', country='" + country
            + "', description=?, interests='" + interests + "', zipcode='" + zipcode + "', designation='"
            + designation + "', gender=" + gender + ", nickname='" + nickname + "', bcity='" + bcity
            + "', bstate='" + bstate + "', bcountry='" + bcountry + "', bzipcode='" + bzipcode + "', hphone='"
            + hphone + "', bphone='" + bphone + "', cphone='" + cphone + "', yim='" + yim + "', aim='" + aim
            + "', msn='" + msn + "', icq='" + icq + "', photolabel='" + photoLabel + "', doclabel='" + docLabel
            + "', street='" + street + "', bstreet='" + bstreet + "', zone='" + zone + "' where loginid="
            + loginid + "";

    PreparedStatement query = null;
    try {
        query = conn.prepareStatement(stmt);
        query.setBytes(1, mydesc);
        query.executeUpdate();
    } catch (SQLException e) {
        throw new BaseDaoException("Error occured while executing update usertab, stmt = " + stmt, e);
    }
}

From source file:com.uit.anonymousidentity.Repository.Nonces.NonceJDBCTemplate.java

@Override
public void store(Nonce nonce) throws SQLException {
    String t_sql = "insert into %s (%s, %s) values (?, ?)";
    String sql = String.format(t_sql, TABLE_NAME, VALUE, SID);
    PreparedStatement pst = dataSource.getConnection().prepareStatement(sql);

    pst.setBytes(1, nonce.getByteArray());
    pst.setString(2, nonce.getIssuerSid());
    pst.executeUpdate();/* ww  w  .ja  v  a  2  s. co m*/
    pst.close();

}

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

public void update(final IdentityAssoc ia) {
    String updateQuery = "update identityassoc" + " set duid=?," + " iatype=?," + " iaid=?," + " state=?"
            + " where id=?";
    getJdbcTemplate().update(updateQuery, new PreparedStatementSetter() {
        @Override//from  w  ww .j ava 2  s.c o m
        public void setValues(PreparedStatement ps) throws SQLException {
            ps.setBytes(1, ia.getDuid());
            ps.setByte(2, ia.getIatype());
            ps.setLong(3, ia.getIaid());
            ps.setByte(4, ia.getState());
            ps.setLong(5, ia.getId());
        }
    });
}

From source file:dao.ContactTagAddQuery.java

public void run(Connection conn, String contactid, String usertags) throws BaseDaoException {

    byte[] mytags = { ' ' };
    if (!RegexStrUtil.isNull(usertags)) {
        mytags = usertags.getBytes();//from  w ww  .  j  a  va 2s .  c  o  m
    }

    PreparedStatement query = null;
    String stmt = "insert into contactstag values(" + contactid + ",?)";
    try {
        query = conn.prepareStatement(stmt);
        query.setBytes(1, mytags);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing contactstag addquery" + stmt, e);
    }
}

From source file:dao.DirPasteQuery.java

/**
 *  Method updates directory path information 
 *  @param conn - the connection/*  w w  w.  j av a 2 s .  c  o  m*/
 *  @param directoryId - the directory Id
 *  @param dirPath - the directory path
 *  @throws BaseDaoException - when error occurs
 **/
public void run(Connection conn, String directoryId, String dirpath) throws BaseDaoException {
    try {

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

        PreparedStatement query = null;
        String stmt = "update directory set dirpath=? where directoryId=" + directoryId + "";
        query = conn.prepareStatement(stmt);
        query.setBytes(1, path);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing update directory path ", e);
    }
}

From source file:com.uit.anonymousidentity.Repository.Nonces.NonceJDBCTemplate.java

@Override
public Nonce find(BigInteger i) throws SQLException {
    String sql = "select * from " + TABLE_NAME + " where " + VALUE + " = ?";
    PreparedStatement pst = dataSource.getConnection().prepareStatement(sql);
    Nonce n = new Nonce();
    pst.setBytes(1, i.toByteArray());
    ResultSet rs = pst.executeQuery();
    if (rs.next()) {
        n.setIssuerSid(rs.getString(SID));
        n.setByteArray(rs.getBytes(VALUE));
        n.setId(rs.getInt(ID));//  w  w  w .  j  a  v  a2  s . c o m
        return n;
    } else
        return null;
}