Example usage for org.apache.commons.dbutils QueryRunner update

List of usage examples for org.apache.commons.dbutils QueryRunner update

Introduction

In this page you can find the example usage for org.apache.commons.dbutils QueryRunner update.

Prototype

public int update(String sql) throws SQLException 

Source Link

Document

Executes the given INSERT, UPDATE, or DELETE SQL statement without any replacement parameters.

Usage

From source file:com.gs.obevo.dbmetadata.impl.dialects.Db2DbMetadataManagerIT.java

protected void setCurrentSchema(QueryRunner jdbc) throws Exception {
    jdbc.update("SET CURRENT PATH " + "SYSIBM,SYSFUN,SYSPROC,SYSIBMADM,DBDEPLOY03");
    jdbc.update("SET SCHEMA " + getSchemaName());
}

From source file:io.stallion.dataAccess.db.mysql.MySqlTickets.java

public void createSequence() {
    List items = db.findRecords("SHOW TABLES LIKE 'stallion_tickets'");
    if (items.size() > 0) {
        return;//w w w . ja  v a2  s. c om
    }
    QueryRunner q = db.newQuery();
    try {
        q.update("CREATE TABLE `stallion_tickets` (\n" + "  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n"
                + "  `ticket_name` varchar(10) DEFAULT NULL,\n" + "  PRIMARY KEY (`id`),\n"
                + "  UNIQUE KEY `ticket_name_unique` (`ticket_name`)\n"
                + ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;");
        db.execute("INSERT INTO stallion_tickets (`ticket_name`) VALUES('a')");
    } catch (Exception e) {
        Log.exception(e, "Error creating tickets table");
    }
}

From source file:com.gs.obevo.dbmetadata.impl.dialects.OracleDbMetadataManagerIT.java

protected void setCurrentSchema(QueryRunner jdbc) throws Exception {
    jdbc.update("alter session set current_schema = " + getSchemaName());
}

From source file:com.fluke.database.dataservice.IntraDayDaoTest.java

@Before
@After//from  w w w .  java  2  s .c om
public void setup() throws SQLException {
    QueryRunner runner = new QueryRunner(DatabaseProperty.getDataSource());
    runner.update("delete from intraday where equity='abcd'");

}

From source file:com.gs.obevo.dbmetadata.impl.dialects.MsSqlDbMetadataManagerIT.java

@Override
protected void setCurrentSchema(QueryRunner jdbc) throws Exception {
    jdbc.update("USE " + getSchemaName());
}

From source file:com.fluke.database.dataservice.EODDao.java

public void deleteLastData() {
    try {//from   w  w  w. j  a v  a2s .c o  m
        String sql = "  delete from EOD where date =  (select maxD from (select max(date) as maxD from EOD as x) as y) ;";
        QueryRunner run = new QueryRunner(DatabaseProperty.getDataSource());
        run.update(sql);
    } catch (SQLException ex) {
        Logger.getLogger(EODDao.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:io.apiman.gateway.engine.jdbc.JdbcMetricsTest.java

@Before
public void reset() throws SQLException {
    QueryRunner run = new QueryRunner(ds);
    run.update("DELETE FROM gw_requests");
}

From source file:gr.osmosis.rcpsamples.contact.db.derby.DerbyContactsDAO.java

public boolean dropTable() {

    try {/*w w  w .ja v  a  2s.com*/
        StringBuffer sbDrop = new StringBuffer();

        sbDrop.append("DROP TABLE APP.CONTACTS");

        DataSource d = DerbyDAOFactory.getDataSource();
        QueryRunner run = new QueryRunner(d);

        run.update(sbDrop.toString());

    } catch (SQLException ex) {
        ex.printStackTrace();
        return false;
    }

    return true;
}

From source file:gr.osmosis.rcpsamples.contact.db.derby.DerbyContactsDAO.java

public boolean createTable() {

    try {/*  w ww.j  a v  a  2 s.  co  m*/
        StringBuffer sbCreate = new StringBuffer();

        sbCreate.append("CREATE TABLE APP.CONTACTS (");
        sbCreate.append("ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),");
        sbCreate.append("FNAME VARCHAR(30), ");
        sbCreate.append("LNAME VARCHAR(30),");
        sbCreate.append("PHONE VARCHAR(30),");
        sbCreate.append("ADDRESS VARCHAR(30),");
        sbCreate.append("CITY VARCHAR(30),");
        sbCreate.append("ZIP VARCHAR(30),");
        sbCreate.append("PRIMARY KEY(ID) )");

        DataSource d = DerbyDAOFactory.getDataSource();
        QueryRunner run = new QueryRunner(d);

        run.update(sbCreate.toString());

    } catch (SQLException ex) {
        ex.printStackTrace();
        return false;
    }

    return true;
}

From source file:gr.osmosis.rcpsamples.contact.db.derby.DerbyContactsDAO.java

public boolean deleteContact(int id) {

    int rows = 0;

    try {/*from  w w  w .ja v  a2 s . c om*/
        StringBuffer sbDelete = new StringBuffer();

        sbDelete.append("DELETE FROM ");
        sbDelete.append(ContactsConstants.CONTACTS_TABLE_NAME);
        sbDelete.append(" WHERE ");
        sbDelete.append(ContactsConstants.CONTACTS_COL_ID + " = " + id);

        DataSource d = DerbyDAOFactory.getDataSource();
        QueryRunner run = new QueryRunner(d);

        rows = run.update(sbDelete.toString());

        if (rows != 1) {
            throw new SQLException("executeUpdate return value: " + rows);
        }

    } catch (SQLException ex) {
        ex.printStackTrace();
        return false;
    }

    return true;

}