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, Object... params) throws SQLException 

Source Link

Document

Executes the given INSERT, UPDATE, or DELETE SQL statement.

Usage

From source file:org.gaixie.jibu.security.service.SettingServiceTest.java

@After
public void tearDown() {
    Connection conn = null;/*w ww.jav  a 2  s.  c  o  m*/
    try {
        conn = ConnectionUtils.getConnection();
        QueryRunner run = new QueryRunner();
        run.update(conn, "DELETE from user_setting_map");
        run.update(conn, "DELETE from settings");
        run.update(conn, "DELETE from userbase");
        DbUtils.commitAndClose(conn);
    } catch (SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        System.out.println(e.getMessage());
    }
}

From source file:org.gaixie.jibu.security.service.UserServiceTest.java

@After
public void tearDown() {
    Connection conn = null;//from  w ww.  ja  v  a2s.c o  m
    try {
        conn = ConnectionUtils.getConnection();
        QueryRunner run = new QueryRunner();
        run.update(conn, "DELETE from userbase");
        DbUtils.commitAndClose(conn);
    } catch (SQLException e) {
        DbUtils.rollbackAndCloseQuietly(conn);
        System.out.println(e.getMessage());
    }
}

From source file:org.kaaproject.kaa.server.datamigration.utils.datadefinition.DataDefinition.java

/**
 * Drop foreign key with autogenerated name based on the table where constrain declared and
 * referenced table name.// w ww.  j  a va2 s .  c o m
 */
public void dropUnnamedFk(String tableName, String referencedTableName) throws SQLException {
    QueryRunner runner = new QueryRunner();
    String query = String.format(QUERY_FIND_FK_NAME, tableName, referencedTableName);
    String fkName = runner.query(connection, query, rs -> rs.next() ? rs.getString(1) : null);
    if (fkName != null) {
        runner.update(connection, "ALTER TABLE " + tableName + " DROP FOREIGN KEY " + fkName);
    } else {
        System.err.println("FK name not found");
    }
}

From source file:org.mule.module.db.integration.executeddl.AbstractExecuteDdlTestCase.java

@Before
public void deleteTestDdlTable() throws Exception {

    Connection connection = null;
    try {// w  w  w  .j  a v a  2  s  .c om
        DataSource dataSource = getDefaultDataSource();
        connection = dataSource.getConnection();

        QueryRunner qr = new QueryRunner(dataSource);
        qr.update(connection, "DROP TABLE TestDdl");
    } catch (SQLException e) {
        // Ignore: table does not exist
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}

From source file:org.mule.module.db.integration.model.AbstractTestDatabase.java

public static void executeDdl(Connection connection, String ddl) throws SQLException {
    QueryRunner qr = new QueryRunner();
    qr.update(connection, ddl);
}

From source file:org.mule.module.db.integration.model.AbstractTestDatabase.java

public void executeUpdate(Connection connection, String updateSql) throws SQLException {
    QueryRunner qr = new QueryRunner();
    int updated = qr.update(connection, updateSql);

    if (logger.isDebugEnabled()) {
        logger.debug(updated + " rows updated");
    }/*from w  w  w . j  a  v a2s .  co  m*/
}

From source file:org.mule.module.db.integration.model.AbstractTestDatabase.java

public final void populatePlanetTable(Connection connection, Planet[] testValues) throws SQLException {
    QueryRunner qr = new QueryRunner();

    for (Planet planet : testValues) {
        int updated = qr.update(connection, getInsertPlanetSql(planet.getName(), planet.getPosition()));

        if (logger.isDebugEnabled()) {
            logger.debug(updated + " rows updated");
        }/* w  w  w.j  a  v  a  2s  .  co m*/
    }
}

From source file:org.mule.module.db.integration.model.AbstractTestDatabase.java

private void populateAlienTable(Connection connection, Alien[] testValues) throws SQLException {
    QueryRunner qr = new QueryRunner();

    for (Alien alien : testValues) {
        int updated = qr.update(connection, getInsertAlienSql(alien));

        if (logger.isDebugEnabled()) {
            logger.debug(updated + " rows updated");
        }/*from  w  ww.j  a  v a  2s  .co  m*/
    }
}

From source file:org.mule.transport.jdbc.functional.AbstractJdbcFunctionalTestCase.java

protected void createTable() throws Exception {
    QueryRunner qr = jdbcConnector.getQueryRunner();
    qr.update(jdbcConnector.getConnection(),
            "CREATE TABLE TEST(ID INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 0)  NOT NULL PRIMARY KEY,TYPE INTEGER,DATA VARCHAR(255),ACK TIMESTAMP,RESULT VARCHAR(255))");
    logger.debug("Table created");
}

From source file:org.mule.transport.jdbc.functional.AbstractJdbcFunctionalTestCase.java

protected void deleteTable() throws Exception {
    QueryRunner qr = jdbcConnector.getQueryRunner();
    int updated = qr.update(jdbcConnector.getConnection(), "DELETE FROM TEST");
    logger.debug(updated + " rows deleted");
}