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

/**
 * This method deletes cobrand for a directory
 * This method can be invoked only either the admins or the authors of this directory
 * @param conn the connection// w  w w.  j av  a 2  s.c o  m
 * @param cid the category id
 * @param ownerid the id of the owner
 * @exception BaseDaoException
 */
public void run(Connection conn, String directoryId) throws BaseDaoException {

    try {
        PreparedStatement stmt = conn
                .prepareStatement("delete from dircobrand where directoryid=" + directoryId + "");
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error executing db query, delete from dircobrand where directoryid="
                + directoryId + " Error=" + e.getMessage(), e);
    }
}

From source file:dao.PblogTagDeleteQuery.java

/**
 *   This method deletes profile of the user 
 *   @param conn - the connection// w w  w .j  a  v  a 2s.  c  o m
 *   @param loginid - the loginid
 *   @throws BaseDaoException - when error occurs
 **/
public void run(Connection conn, String loginid) throws BaseDaoException {

    try {
        PreparedStatement stmt = conn
                .prepareStatement("delete LOW_PRIORITY from pblogtags where ownerid=" + loginid + "");
        stmt.executeUpdate();
    } catch (Exception e) {
        logger.warn("Error occured while executing  pblog query ", e);
        throw new BaseDaoException("Error occured while executing pblog query ", e);
    }
}

From source file:com.taobao.tddl.jdbc.group.integration.SpringTest.java

@Test
public void springTest() throws Exception {

    Connection conn = ds.getConnection();

    //Statementcrud
    Statement stmt = conn.createStatement();
    assertEquals(stmt.executeUpdate("insert into crud(f1,f2) values(10,'str')"), 1);
    assertEquals(stmt.executeUpdate("update crud set f2='str2'"), 1);
    ResultSet rs = stmt.executeQuery("select f1,f2 from crud");
    rs.next();/*from w w w  . ja v a 2s . c  om*/
    assertEquals(rs.getInt(1), 10);
    assertEquals(rs.getString(2), "str2");
    assertEquals(stmt.executeUpdate("delete from crud"), 1);
    rs.close();
    stmt.close();

    //PreparedStatementcrud
    String sql = "insert into crud(f1,f2) values(10,'str')";
    PreparedStatement ps = conn.prepareStatement(sql);
    assertEquals(ps.executeUpdate(), 1);
    ps.close();

    sql = "update crud set f2='str2'";
    ps = conn.prepareStatement(sql);
    assertEquals(ps.executeUpdate(), 1);
    ps.close();

    sql = "select f1,f2 from crud";
    ps = conn.prepareStatement(sql);
    rs = ps.executeQuery();
    rs.next();
    assertEquals(rs.getInt(1), 10);
    assertEquals(rs.getString(2), "str2");
    rs.close();
    ps.close();

    sql = "delete from crud";
    ps = conn.prepareStatement(sql);
    assertEquals(ps.executeUpdate(), 1);
    ps.close();

    conn.close();
}

From source file:dao.ColMsgsDeleteQuery.java

/**
 * This method deletes all collmessages that match thread id
 * @param conn - the connection//from  w  w w .ja  va2s .  c o m
 * @param tidStr - the threadid 
 * @throws BaseDaoException - when error occurs
 **/
public void run(Connection conn, String tidStr) throws BaseDaoException {

    Integer tid = new Integer(tidStr);
    try {
        PreparedStatement stmt = conn
                .prepareStatement("delete LOW_PRIORITY from collmessages where tid=" + tid + "");
        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.DeleteColCobrandPerCollabrumQuery.java

/**
 * Delete all collabrum topics in a collabrum 
 * @param conn the connection//from   w w  w .  ja  v a 2 s.  c  o m
 * @param collabrumId the collabrum id
 * @exception BaseDaoException
 */
public void run(Connection conn, String collabrumId) throws BaseDaoException {

    //Integer cid = new Integer(collabrumId);
    try {
        PreparedStatement stmt = conn
                .prepareStatement("delete from collcobrand where collabrumid=" + collabrumId + "");
        stmt.executeUpdate();
    } catch (Exception e) {
        logger.warn("DeleteColCobrandPerCollabrumQuery() error occured while executing db query ", e);
        throw new BaseDaoException("Error occured while executing db query ", e);
    }
}

From source file:dao.DirBlobTagsDeleteAllQuery.java

/**
 * This method deletes tags for dirblobs that belong to a directory
 * This method can be invoked only either the admins or the authors of this directory
 * @param conn the connection/*from  w  ww . j  a  v  a  2  s.c om*/
 * @param cid the category id
 * @param ownerid the id of the owner
 * @exception BaseDaoException
 */
public void run(Connection conn, String directoryId) throws BaseDaoException {

    try {
        PreparedStatement stmt = conn
                .prepareStatement("delete from dirblobtags where directoryid=" + directoryId + "");
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error executing db query, delete from dirblobtags where directoryid="
                + directoryId + " Error=" + e.getMessage(), e);
    }
}

From source file:dao.DirWebsitesDeleteAllQuery.java

/**
 * This method deletes images for a directory
 * This method can be invoked only either the admins or the authors of this directory
 * @param conn the connection/*from w w w .java  2 s  .  co m*/
 * @param cid the category id
 * @param ownerid the id of the owner
 * @exception BaseDaoException
 */
public void run(Connection conn, String directoryId) throws BaseDaoException {

    try {
        PreparedStatement stmt = conn
                .prepareStatement("delete from dirwebsites where directoryid=" + directoryId + "");
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error executing db query, delete from dirwebsites where directoryid="
                + directoryId + " Error=" + e.getMessage(), e);
    }
}

From source file:dao.DisplaypageFilesUpdateQuery.java

public void run(Connection conn, int files, String loginid) throws BaseDaoException {
    try {/* w w w  . j  a v a2s .c  o  m*/
        PreparedStatement stmt = conn
                .prepareStatement("update displayuser set files=" + files + " where loginid=" + loginid + "");
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing update displayuser ", e);
    }
}

From source file:dao.PblogTopicAttrDeleteAllQuery.java

/**
 *   This method deletes pblog topic attributes of the user 
 *   @param conn - the connection/*from   w  w w.  java2s.c  o  m*/
 *   @param loginid - the loginid
 *   @throws BaseDaoException - when error occurs
 **/
public void run(Connection conn, String loginid) throws BaseDaoException {
    try {
        PreparedStatement stmt = conn
                .prepareStatement("delete LOW_PRIORITY from pblogtopicattr where loginid=" + loginid + "");
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing pblog query ", e);
    }
}

From source file:dao.PblogTopicDeleteAllQuery.java

/**
  * Deletes all personalblogs topic//from  www  .j  a  v  a2 s .  c o m
  * @param conn the connection
  * @param memberid the memberid 
  */
public void run(Connection conn, String memberid) throws BaseDaoException {
    try {
        PreparedStatement stmt = conn
                .prepareStatement("delete LOW_PRIORITY from pblogtopics where pblogid=" + memberid + "");
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing db query ", e);
    }
}