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

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

    Integer myZoom = 100;//from ww w.  j  a  v  a 2  s .  c o m
    if (!RegexStrUtil.isNull(zoom)) {
        myZoom = new Integer(zoom);
    }

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

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

From source file:dao.CollabrumUpdateQuery.java

/**
 * This method is used update <code>Collabrum</code> bean
 * @param conn the connection passed to this.
 * @param collabrumId the collabrumId/*from w  w w.  java2s  .  c om*/
 * @param desc the description
 * @param keywords the keywords for the directory
 * @exception BaseDaoException
 */
public void run(Connection conn, String collabrumid, String desc, String keywords) throws BaseDaoException {

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

    PreparedStatement query = null;
    String stmt = null;
    try {
        stmt = "update collabrum set coldesc=? where collabrumid=" + collabrumid + "";
        query = conn.prepareStatement(stmt);
        query.setBytes(1, mydesc);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured executing directory update query + query = " + stmt, e);
    }
}

From source file:dao.DirCobrandUpdateFooterQuery.java

/**
 * This method is not called by spring.//from w w w . j  av a2 s .  c om
 *
 * @param conn the connection passed to this.
 * @param directoryid the directoryid 
 * @param footer the footer
 * @exception BaseDaoException
 */
public void run(Connection conn, String directoryid, byte[] footer) throws BaseDaoException {

    PreparedStatement query = null;
    String stmt = null;

    try {
        stmt = "update dircobrand set footer=? where directoryid=" + directoryid + " limit 1";
        query = conn.prepareStatement(stmt);
        query.setBytes(1, footer);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing dircobrand updating query, query = " + stmt,
                e);
    }
}

From source file:dao.DirCobrandUpdateHeaderQuery.java

/**
 * This method is not called by spring.//from   w ww .  j  a va 2 s  .  co m
 *
 * @param conn the connection passed to this.
 * @param directoryid the directoryid 
 * @param header the header
 * @exception BaseDaoException
 */
public void run(Connection conn, String directoryid, byte[] header) throws BaseDaoException {

    PreparedStatement query = null;
    String stmt = null;

    try {
        stmt = "update dircobrand set header=? where directoryid=" + directoryid + " limit 1";
        query = conn.prepareStatement(stmt);
        query.setBytes(1, header);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing dircobrand updating query, query = " + stmt,
                e);
    }
}

From source file:dao.ColCobrandUpdateFooterQuery.java

/**
 * This method is not called by spring./* w  ww  .j  av a  2 s. c  o  m*/
 *
 * @param conn the connection passed to this.
 * @param collabrumid the collabrumid 
 * @param footer the footer
 * @exception BaseDaoException
 */
public void run(Connection conn, String collabrumid, byte[] footer) throws BaseDaoException {

    PreparedStatement query = null;
    String stmt = null;

    try {
        stmt = "update collcobrand set footer=? where collabrumid=" + collabrumid + " limit 1";
        query = conn.prepareStatement(stmt);
        query.setBytes(1, footer);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing collcobrand updating query, query = " + stmt,
                e);
    }
}

From source file:dao.ColCobrandUpdateHeaderQuery.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 header the header
 * @exception BaseDaoException
 */
public void run(Connection conn, String collabrumid, byte[] header) throws BaseDaoException {

    PreparedStatement query = null;
    String stmt = null;

    try {
        stmt = "update collcobrand set header=? where collabrumid=" + collabrumid + " limit 1";
        query = conn.prepareStatement(stmt);
        query.setBytes(1, header);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing collcobrand updating query, query = " + stmt,
                e);
    }
}

From source file:dao.DirImageUpdateQuery.java

/**
 * This method is not called by spring./*from   w w  w .  j av a 2  s  .  c  om*/
 *
 * @param conn the connection passed to this.
 * @param directoryid the category id
 * @param dirname the directory name
 * @param keywords the keywords
 * @param parentname the parent of this category or directory
 * @param stateid the state id
 * @param catdesc the category description
 * @param ownerid the owner id
 * @exception BaseDaoException
 */
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();
    }

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

From source file:dao.CarryonRecentUpdateQuery.java

/**
 * This method is not called by spring./*  w ww  .j a va 2s  . c  o m*/
 *
 * @param conn the connection is passed to this method
 * @param btitle the title of the blob
 * @param zoom the zoom for the images
 * @param entryid 
 */
public void run(Connection conn, String btitle, String zoom, String entryid, String loginid, boolean isFile,
        String caption) throws BaseDaoException {

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

    /**
          *  Zoom is not applicable to files. Don't update zoom for file blobs
          */
    StringBuffer query = new StringBuffer();
    try {
        if (isFile) {
            query.append("update pblob set btitle='" + btitle + "', caption='" + caption + "', zoom=" + zoom
                    + " where entryid=" + entryid + " and loginid=" + loginid + "");
            PreparedStatement stmt = conn.prepareStatement("update pblob set btitle='" + btitle
                    + "', caption=? where entryid=" + entryid + " and loginid=" + loginid + "");
            stmt.setBytes(1, capBytes);
            stmt.executeUpdate();
        } else {
            query.append("update pblob set btitle='" + btitle + "', caption='" + caption + "', zoom=" + zoom
                    + " where entryid=" + entryid + " and loginid=" + loginid + "");
            PreparedStatement stmt = conn
                    .prepareStatement("update pblob set btitle='" + btitle + "', caption=?, zoom=" + zoom
                            + " where entryid=" + entryid + " and loginid=" + loginid + "");
            stmt.setBytes(1, capBytes);
            stmt.executeUpdate();
        }
    } catch (Exception e) {
        logger.warn("Error occured while executing CarryonRecentUpdateQuery, query=" + query.toString(), e);
        throw new BaseDaoException("Error occured while executing update pblob ", e);
    }
}

From source file:dao.CarryonUpdateQuery.java

/**
 * This method is not called by spring.// w ww  .jav a2 s. c  om
 *
 * @param conn the connection is passed to this method
 * @param btitle the title of the blob
 * @param zoom the zoom for the images
 * @param entryid 
 */
public void run(Connection conn, String btitle, String zoom, String entryid, String loginid, boolean isFile,
        String caption) throws BaseDaoException {

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

    /**
          *  Zoom is not applicable to files. Don't update zoom for file blobs
          */
    StringBuffer query = new StringBuffer();
    try {
        if (isFile) {
            query.append("update carryon set btitle='" + btitle + "', caption='" + caption + "', zoom=" + zoom
                    + " where entryid=" + entryid + " and loginid=" + loginid + "");
            PreparedStatement stmt = conn.prepareStatement("update carryon set btitle='" + btitle
                    + "', caption=? where entryid=" + entryid + " and loginid=" + loginid + "");
            stmt.setBytes(1, capBytes);
            stmt.executeUpdate();
        } else {
            query.append("update carryon set btitle='" + btitle + "', caption='" + caption + "', zoom=" + zoom
                    + " where entryid=" + entryid + " and loginid=" + loginid + "");
            PreparedStatement stmt = conn
                    .prepareStatement("update carryon set btitle='" + btitle + "', caption=?, zoom=" + zoom
                            + " where entryid=" + entryid + " and loginid=" + loginid + "");
            stmt.setBytes(1, capBytes);
            stmt.executeUpdate();
        }
    } catch (Exception e) {
        logger.warn("Error occured while executing CarryonUpdateQuery, query=" + query.toString(), e);
        throw new BaseDaoException("Error occured while executing update carryon ", e);
    }
}

From source file:dao.CollabrumAddQuery.java

/**
 * This method is not called by spring./*from  ww  w .  j  a  v a 2 s  .  c  o m*/
 *
 * @param conn the connection passed to this.
 * @param dirname the directory name
 * @param keywords the keywords
 * @param catdsec the description of this category or directory
 * @param catlink the link of this category
 * @param catpath the path of this category
 * @param stateid the stateid of this category
 * @param ownerid the owner id 
 * @exception BaseDaoException
 */
public void run(Connection conn, String name, String userid, String desc, String keywords, String style)
        throws BaseDaoException {

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

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

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

    PreparedStatement stmt = null;
    String query = null;

    try {
        query = "insert into collabrum values (0," + userid + ",?,?,?,'" + style + "',0)";
        stmt = conn.prepareStatement(query);
        stmt.setBytes(1, myname);
        stmt.setBytes(2, mydesc);
        stmt.setBytes(3, mykeywords);
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing directory addquery, query = " + query, e);
    }
}