Example usage for java.sql PreparedStatement executeUpdate

List of usage examples for java.sql PreparedStatement executeUpdate

Introduction

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

Prototype

int executeUpdate() throws SQLException;

Source Link

Document

Executes the SQL statement in this PreparedStatement object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

Usage

From source file:com.softberries.klerk.dao.AddressDao.java

public void deleteAll(Connection conn) throws SQLException {
    PreparedStatement st = conn.prepareStatement(SQL_DELETE_ALL_ADDRESSES);
    int i = st.executeUpdate();
    System.out.println("i: " + i);
    if (i == -1) {
        System.out.println("db error : " + SQL_DELETE_ALL_ADDRESSES);
    }//from  w  w  w.j av  a2s .  co m
}

From source file:dao.CarryonHitsUpdateQuery.java

/**
 * This method is not called by spring.//w ww .j av  a 2s .  com
 *
 * @param conn the connection is passed to this method
 * @param entryid 
 * @param loginid loginid
 * @param hits hits
 */
public void run(Connection conn, String loginid, String entryid, String hits) throws BaseDaoException {
    try {
        PreparedStatement stmt = conn.prepareStatement("update carryonhits set hits='" + hits
                + "' where entryid=" + entryid + " and loginid=" + loginid + "");
        stmt.executeUpdate();
        String myquery = "update carryonhits set hits='" + hits + "' where entryid=" + entryid + " and loginid="
                + loginid + "";
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing update carryonhits ", e);
    }
}

From source file:dao.DirectoryDeleteAuthorQuery.java

/**
 * This query deletes an author (only one) matching this directoryid and ownerid
 * @param conn the connection//from  w w w .ja  v a  2 s . c  om
 * @param did the directory id
 * @param ownerid the owner id
 * @exception BaseDaoException
 */
public void run(Connection conn, String did, String ownerid) throws BaseDaoException {

    try {
        PreparedStatement stmt = conn.prepareStatement("delete LOW_PRIORITY from diradmin where directoryid="
                + did + " and ownerid=" + ownerid + " limit 1");
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException(
                "Error occured while executing delete from diradmin where directoryid=" + did, e);
    }
}

From source file:biblivre3.cataloging.bibliographic.IndexDAO.java

public final boolean delete(final IndexTable table, final IndexDTO index) {
    Connection con = null;/*from   www.  j a va2s.com*/
    try {
        con = getDataSource().getConnection();
        final String sql = " DELETE FROM " + table.getTableName() + " WHERE record_serial = ?;";

        final PreparedStatement pst = con.prepareStatement(sql);
        pst.setInt(1, index.getRecordSerial());

        return pst.executeUpdate() > 0;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new ExceptionUser("ERROR_BIBLIO_DAO_EXCEPTION");
    } finally {
        closeConnection(con);
    }
}

From source file:dao.ColMessageDeleteQuery.java

/**
 * Deletes a collabrum message//from   w ww  .  j av a 2 s .  c  o m
 * @param conn the connection
 * @param ridStr the reply id
 * @param memberid the id of the member
 * @param isAdmin - true if the user is a DiaryAdmin or a Moderator for this collabrum
 * @exception BaseDaoException
 */
public void run(Connection conn, String ridStr, String memberid, boolean isAdmin) throws BaseDaoException {

    Integer rid = new Integer(ridStr);
    Long ownerid = new Long(memberid);

    /**
          *  If user is an admin/organizer, don't check ownerid
          **/
    try {
        if (isAdmin) {
            PreparedStatement stmt = conn
                    .prepareStatement("delete LOW_PRIORITY from collmessages where rid=" + rid + " limit 1");
            stmt.executeUpdate();
        } else {
            PreparedStatement stmt = conn.prepareStatement(
                    "delete from collmessages where rid=" + rid + " and ownerid='" + ownerid + "' limit 1");
            stmt.executeUpdate();
        }
    } catch (Exception e) {
        logger.warn("Error occured while executing db query ", e);
        throw new BaseDaoException("Error occured while executing db query ", e);
    }
}

From source file:dao.ContactDeleteQuery.java

/**
 *   This method deletes yourkeywords //w  ww  .j  a v  a2  s .  c  om
 *   @param conn - the connection
 *   @param contactid - the contactid
 *   @param ownerid - the ownerid
 *   @throws BaseDaoException - when error occurs
 **/
public void run(Connection conn, String contactid, String ownerid) throws BaseDaoException {

    try {
        PreparedStatement stmt = conn.prepareStatement("delete LOW_PRIORITY from hdcontacts where contactid="
                + contactid + " and ownerid=" + ownerid + " limit 1");
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing hdcontacts query ", e);
    }
}

From source file:com.cloudera.sqoop.manager.DirectPostgreSQLExportManualTest.java

@Override
protected Connection getConnection() {
    try {/*from   w w  w. ja  v a 2  s . c om*/
        Connection conn = dbConf.getConnection();
        conn.setAutoCommit(false);
        PreparedStatement stmt = conn.prepareStatement("SET extra_float_digits TO 0");
        stmt.executeUpdate();
        conn.commit();
        return conn;
    } catch (SQLException sqlE) {
        LOG.error("Could not get connection to test server: " + sqlE);
        return null;
    } catch (ClassNotFoundException cnfE) {
        LOG.error("Could not find driver class: " + cnfE);
        return null;
    }
}

From source file:dao.PblogTopicDeleteQuery.java

/**
  * Deletes a pblog topic//from   w  w  w  .ja v a2  s .  c  om
  * @param conn the connection
  * @param tidStr the threadid of this topic
  * @param memberid the memberid 
  */
public void run(Connection conn, String tidStr, String memberid) throws BaseDaoException {
    //Integer tid = new Integer(tidStr);
    //Long ownerid = new Long(memberid);

    try {
        PreparedStatement stmt = conn.prepareStatement("delete LOW_PRIORITY from pblogtopics where tid="
                + tidStr + " and pblogid=" + memberid + " limit 1");
        stmt.executeUpdate();
    } catch (Exception e) {
        logger.warn("Error occured while executing db query ", e);
        throw new BaseDaoException("Error occured while executing db query ", e);
    }
}

From source file:AddProductModel.AddProductWS.java

@WebMethod(operationName = "addProduct")
public int addProduct(@WebParam(name = "access_token") String access_token,
        @WebParam(name = "product_name") String product_name,
        @WebParam(name = "description") String description, @WebParam(name = "price") String price,
        @WebParam(name = "img_name") String img_name, @WebParam(name = "img_byte") byte[] img_byte)
        throws ProtocolException, IOException, ParseException {
    int status = 0;
    Connection dbConn = DbConnectionManager.getConnection();
    java.util.Date date = new java.util.Date();
    java.sql.Date dateadded = new java.sql.Date(date.getTime());
    java.sql.Time timeadded = new java.sql.Time(date.getTime());
    int purchases = 0;

    String targetIS = "ValidateToken";
    String urlParameters = "access_token=" + access_token;
    HttpURLConnection urlConn = UrlConnectionManager.doReqPost(targetIS, urlParameters);
    String resp = UrlConnectionManager.getResponse(urlConn);

    JSONParser parser = new JSONParser();
    JSONObject obj = (JSONObject) parser.parse(resp);
    String statusResp = (String) obj.get("status");
    String username = (String) obj.get("username");

    switch (statusResp) {
    case "valid":
        try {//from   w  w w.  j  a va  2s .c o m
            String image_path = uploadImage(img_byte, img_name);
            String query = "INSERT INTO catalogue(productname,price,productdesc,username,dateadded,timeadded,purchases,imagepath) VALUES ('"
                    + product_name + "','" + price + "','" + description + "','" + username + "','" + dateadded
                    + "','" + timeadded + "','" + purchases + "','" + image_path + "')";
            PreparedStatement ps = dbConn.prepareStatement(query);
            int i = ps.executeUpdate();
        } catch (SQLException ex) {
            System.out.println("Inser to database failed: An Exception has occurred! " + ex);
        } finally {
            if (dbConn != null) {
                try {
                    dbConn.close();
                } catch (SQLException e) {
                    System.out.println(e);
                }
                dbConn = null;
            }
        }
        status = 1;
        break;
    case "non-valid":
        status = 2;
        break;
    default:
        status = 3;
        break;
    }
    return status;
}

From source file:dao.CarryonHitsUpdateTitleQuery.java

/**
 * This method is not called by spring.//  w  ww . j  av a2s. c o  m
 *
 * @param conn the connection is passed to this method
 * @param entryid 
 * @param loginid loginid
 * @param btitle btitle
 */
public void run(Connection conn, String loginid, String entryid, String btitle) throws BaseDaoException {
    try {
        PreparedStatement stmt = conn.prepareStatement("update carryonhits set btitle='" + btitle
                + "' where entryid=" + entryid + " and loginid=" + loginid + "");
        stmt.executeUpdate();
        String myquery = "update carryonhits set btitle='" + btitle + "' where entryid=" + entryid
                + " and loginid=" + loginid + "";
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing update carryonhits ", e);
    }
}