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

/**
 * This class is used to block a member from accessing collabrum
 * @param conn - the connection//  w  w  w  .ja va2 s.  c o m
 * @param collabrumId - the collabrumId
 * @param myownerId - the ownerId
 * @throws BaseDaoException - when error occurs 
 */
public void run(Connection conn, String collabrumid, String myownerid) throws BaseDaoException {
    PreparedStatement query = null;
    try {
        String stmt = "insert into collblock values(" + collabrumid + ", " + myownerid + ")";
        query = conn.prepareStatement(stmt);
        query.executeUpdate();
    } catch (Exception e) {
        logger.warn("Error occured while executing collmembers addquery", e);
        throw new BaseDaoException("Error occured while executing collmembers addquery", e);
    }
}

From source file:dao.ContactAddShareQuery.java

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

    PreparedStatement query = null;
    String stmt = "insert into sharecontact values(" + loginid + ", " + contactid + "," + destid + ")";
    try {/*from www  . ja va  2s.  c  o  m*/
        query = conn.prepareStatement(stmt);
        query.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing sharecontacts addquery" + stmt, e);
    }
}

From source file:com.uiip.gviviani.esercizioweekend.interfaces.impl.DefaultPersonDAO.java

@Override
public boolean cancellaPerson(String numero) {
    MysqlDataSource datasource = new MysqlDataSource();
    datasource.setUser("root");
    datasource.setPassword("root");
    datasource.setUrl("jdbc:mysql://localhost:3306/Rubrica");
    Connection connection = null;
    try {/*from   w w  w  .java  2 s .  c  o  m*/
        connection = datasource.getConnection();
        String sql = "DELETE FROM contatti " + "WHERE numero = ? ;";
        PreparedStatement stat = connection.prepareStatement(sql);
        stat.setString(1, numero);
        if (stat.executeUpdate() > 0) {
            return true;
        }
    } catch (SQLException e) {
        logger.error(e);
    } finally {
        DbUtils.closeQuietly(connection);
    }
    return false;
}

From source file:dao.GuestMessageAddQuery.java

/**
 * This method is used to add guestbook information
 * @param conn - the connection/*from   ww  w .jav a 2 s . com*/
 * @param loginid - the loginid (whose guestbook is updated)
 * @param guestid - the guestid 
 * @param message - the guestbook entry
 * @throws BaseDaoException - when error ocurrs
 **/
public void run(Connection conn, String loginid, String guestid, String message) throws BaseDaoException {

    try {
        PreparedStatement stmt = conn.prepareStatement("insert into guestbook values(0, " + loginid + ", "
                + guestid + ", CURRENT_TIMESTAMP(),'" + message + "')");
        stmt.executeUpdate();
    } catch (Exception e) {
        throw new BaseDaoException("Error occured executing insert into guestbook ", e);
    }
}

From source file:dao.HdprofileAddQuery.java

public void run(Connection conn, String[] params) throws BaseDaoException {

    String informpm = params[0];//from  w ww  .  j  a  va2  s.co m
    String informbb = params[1];
    String informfd = params[2];

    try {
        PreparedStatement stmt = conn.prepareStatement("insert into hdprofile values (" + "LAST_INSERT_ID()"
                + ", " + informpm + ", " + informbb + ", " + informfd + ")");
        stmt.executeUpdate();

        // for oracle, it would be something like
        //stmt.executeUpdate("insert into hdprofile values ("+"loginidseq.currval"+", "+informpm+", "+informbb+", "+informfd+")");
        // where loginidseq is created using CREATE SEQUENCE 
    } catch (Exception e) {
        logger.warn("Error occured while executing hdprofile addquery", e);
        throw new BaseDaoException("Error occured while executing hdprofile addquery", e);
    }
}

From source file:edu.umd.cs.marmoset.modelClasses.CodeMetrics.java

public void insert(Connection conn) throws SQLException {
    String insert = Queries.makeInsertStatementUsingSetSyntax(ATTRIBUTE_NAME_LIST, TABLE_NAME, false);
    PreparedStatement stmt = null;
    try {/*from   w w w. ja  v a 2s  . c  o  m*/
        stmt = conn.prepareStatement(insert);

        putValues(stmt, 1);

        stmt.executeUpdate();
    } finally {
        Queries.closeStatement(stmt);
    }
}

From source file:de.bley.word.filewriter.WriterJdbc.java

/**
 *
 * Schreibt einen Datensatz in eine Tabelle.
 *
 * @param col/*from ww  w .  j a  va  2  s. co  m*/
 * @param text
 * @param flag
 *
 */
@Override
public void writeInFile(final String col, final String text, final boolean flag) {

    Connection connection = JdbcConnection.getInstance().connect();

    if (connection != null) {
        try {
            PreparedStatement ps = connection.prepareStatement("INSERT INTO APP.MYTABLE (DATA) VALUES (?)");
            ps.setString(1, text);
            ps.executeUpdate();
            connection.close();
        } catch (SQLException ex) {
            log.debug("execute of Query (write in file)", ex);
        }
    }
}

From source file:com.mycompany.spring_chatdemo.ConnectDB.java

public void insertDB(Message message) throws SQLException {
    try {//from w ww .j  a va2  s  . com
        String query = "INSERT INTO " + table + " VALUES (?, ?, ?)";

        connection = dataSource.getConnection();
        PreparedStatement ps = connection.prepareStatement(query);
        ps.setString(1, message.getFrom());
        ps.setString(2, message.getTo());
        ps.setString(3, message.getMessage());
        ps.executeUpdate();
        ps.close();
    } catch (SQLException ex) {
        Logger.getLogger(ConnectDB.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (connection != null)
            connection.close();
    }

}

From source file:dao.ShareuserAddQuery.java

/**
 * This method is used to add shareuser information
 * @param conn - the connection// w  w w  .  j  av  a2  s .c  o  m
 * @param loginid - the loginid (the user who is sharing his/her information)
 * @param destid - the destid (the user with whom this information is being shared with)
 * @param bphone - the bphone (of loginid)
 * @param cphone - the cphone (of loginid)
 * @param email - the email (of loginid)
 * @param files - the files (of loginid)
 * @throws BaseDaoException - when error ocurrs
 **/
public void run(Connection conn, String loginid, String destid, int bphone, int cphone, int email, int files)
        throws BaseDaoException {
    try {
        PreparedStatement stmt = conn.prepareStatement("insert into shareuser values (" + loginid + ", "
                + destid + ", " + bphone + ", " + cphone + ", " + email + ", " + files + ")");
        stmt.executeUpdate();
    } catch (Exception e) {
        logger.warn("Error occured while executing update shareuser ", e);
        throw new BaseDaoException("Error occured while executing update shareuser ", e);
    }
}

From source file:dao.DirAddChildQuery.java

/**
 * This method is not called by spring.//from w w  w . jav  a  2 s .co  m
 * This method adds an admin into this directory
 * @param conn the connection passed to this.
 * @param dirid the directory id
 * @param ownerid the author id for this directory
 * @exception BaseDaoException
 */
public void run(Connection conn, String dirid, String parentid) throws BaseDaoException {
    PreparedStatement query = null;
    String stmt = null;
    try {
        stmt = "insert into dirtree values (" + dirid + ", " + parentid + ")";
        query = conn.prepareStatement(stmt);
        query.executeUpdate();
        logger.debug("stmt = " + stmt);
    } catch (Exception e) {
        throw new BaseDaoException("Error occured while executing dirtree addquery(), " + stmt, e);
    }
}