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

private int update(Connection conn, boolean closeConn, String sql, Object... params) throws SQLException 

Source Link

Document

Calls update after checking the parameters to ensure nothing is null.

Usage

From source file:com.demo.db.dao.impl.DriverDaoImpl.java

@Override
public int updateByCell(Driver driver) {
    QueryRunner queryRunner = dbHelper.getRunner();

    try {//from   w  ww. jav  a 2s  . com
        int rows = queryRunner.update(dbHelper.getConnection(),
                "update demo_driver set password=? where cell=?", DigestUtils.md5Hex(driver.getPassword()),
                driver.getCell());
        return rows;
    } catch (SQLException e) {
        LOGGER.error("? ?{}", driver);
        throw new RuntimeException("?", e);
    }
}

From source file:com.demo.admin.dao.impl.AdminDriverDaoImpl.java

@Override
public int updateUsedById(Long id, short used) {
    QueryRunner queryRunner = dbHelper.getRunner();
    try {//from w  w w .  j  a v  a2s . c  o m
        int rows = queryRunner.update(dbHelper.getConnection(), "update demo_driver set used=? where id=?",
                used, id);
        return rows;
    } catch (SQLException e) {
        String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
        logger.error("{}??{},{}", methodName, id);
        throw new RuntimeException(e);
    }
}

From source file:com.demo.admin.dao.impl.AdminDriverDaoImpl.java

@Override
public int updateDriverPlaceId(Long id, Long driverPlaceId) {
    QueryRunner queryRunner = dbHelper.getRunner();
    try {//from ww  w. ja  v  a  2 s . c o  m
        int rows = queryRunner.update(dbHelper.getConnection(),
                "update demo_driver set driver_place_id = ? where id=?", driverPlaceId, id);
        return rows;
    } catch (SQLException e) {
        String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
        logger.error("{}??{},{}", methodName, id, driverPlaceId);
        throw new RuntimeException(e);
    }
}

From source file:azkaban.scheduler.JdbcScheduleLoader.java

@Override
public void updateNextExecTime(Schedule s) throws ScheduleManagerException {
    logger.info("Update schedule " + s.getScheduleName() + " into db. ");
    Connection connection = getConnection();
    QueryRunner runner = new QueryRunner();
    try {//from  ww  w.  j  a v  a2s .  co  m

        runner.update(connection, UPDATE_NEXT_EXEC_TIME, s.getNextExecTime(), s.getScheduleId());
    } catch (SQLException e) {
        e.printStackTrace();
        logger.error(UPDATE_NEXT_EXEC_TIME + " failed.", e);
        throw new ScheduleManagerException("Update schedule " + s.getScheduleName() + " into db failed. ", e);
    } finally {
        DbUtils.closeQuietly(connection);
    }
}

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

/**
 * @see io.apiman.gateway.engine.IRegistry#unregisterClient(io.apiman.gateway.engine.beans.Client, io.apiman.gateway.engine.async.IAsyncResultHandler)
 *//*w ww. j a v a2  s .co  m*/
@Override
public void unregisterClient(Client client, IAsyncResultHandler<Void> handler) {
    try {
        QueryRunner run = new QueryRunner(ds);
        run.update("DELETE FROM gw_clients WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$
                client.getOrganizationId(), client.getClientId(), client.getVersion());
        handler.handle(AsyncResultImpl.create((Void) null));
    } catch (SQLException e) {
        handler.handle(AsyncResultImpl.create(
                new PublishingException(Messages.i18n.format("JdbcRegistry.ErrorUnregisteringApp"), e), //$NON-NLS-1$
                Void.class));
    }
}

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

/**
 * @see io.apiman.gateway.engine.IRegistry#retireApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler)
 *///from   w w  w.  j  ava2 s.c  o  m
@Override
public void retireApi(Api api, IAsyncResultHandler<Void> handler) {
    QueryRunner run = new QueryRunner(ds);
    try {
        run.update("DELETE FROM gw_apis WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$
                api.getOrganizationId(), api.getApiId(), api.getVersion());
        handler.handle(AsyncResultImpl.create((Void) null, Void.class));
    } catch (SQLException e) {
        handler.handle(AsyncResultImpl.create(e));
    }
}

From source file:com.demo.db.dao.impl.DriverDaoImpl.java

@Override
public int updateById(Driver driver) {
    QueryRunner queryRunner = dbHelper.getRunner();

    try {/*from   w  ww  .ja  v a 2 s  .c om*/
        List<String> columnList = new LinkedList<String>();
        columnList.add("name");
        for (int i = 0; i < columnList.size(); i++) {
            String strColumn = columnList.get(i);
            columnList.set(i, strColumn + "=?");
        }
        final String strUpdateSet = StringUtils.join(columnList.toArray(), ",");
        if (StringUtils.isBlank(strUpdateSet)) {
            throw new RuntimeException("");
        }
        StringBuilder sb = new StringBuilder();
        sb.append("update demo_driver set ");
        sb.append(strUpdateSet);
        sb.append(" where id=?");
        int rows = queryRunner.update(dbHelper.getConnection(), sb.toString(), driver.getName(),
                driver.getId());
        return rows;
    } catch (SQLException e) {
        LOGGER.error(" ?{}", driver);
        throw new RuntimeException("", e);
    }
}

From source file:azkaban.project.JdbcProjectLoader.java

private void cleanOlderProjectVersionFlows(Connection connection, int projectId, int version)
        throws ProjectManagerException {
    final String DELETE_FLOW = "DELETE FROM project_flows WHERE project_id=? AND version<?";
    QueryRunner runner = new QueryRunner();
    try {//from  www.j  a  v a  2  s  . c om
        runner.update(connection, DELETE_FLOW, projectId, version);
        connection.commit();
    } catch (SQLException e) {
        throw new ProjectManagerException("Error deleting project version flows " + projectId + ":" + version,
                e);
    }
}

From source file:azkaban.project.JdbcProjectLoader.java

private void cleanOlderProjectVersionProperties(Connection connection, int projectId, int version)
        throws ProjectManagerException {
    final String DELETE_PROPERTIES = "DELETE FROM project_properties WHERE project_id=? AND version<?";
    QueryRunner runner = new QueryRunner();
    try {/* w w  w  . j a  v a  2 s  .  c o  m*/
        runner.update(connection, DELETE_PROPERTIES, projectId, version);
        connection.commit();
    } catch (SQLException e) {
        throw new ProjectManagerException(
                "Error deleting project version properties " + projectId + ":" + version, e);
    }
}

From source file:azkaban.project.JdbcProjectLoader.java

private void cleanOlderProjectFiles(Connection connection, int projectId, int version)
        throws ProjectManagerException {
    final String DELETE_PROJECT_FILES = "DELETE FROM project_files WHERE project_id=? AND version<?";
    QueryRunner runner = new QueryRunner();
    try {/*from   w  w w.j  av a 2 s .c om*/
        runner.update(connection, DELETE_PROJECT_FILES, projectId, version);
        connection.commit();
    } catch (SQLException e) {
        throw new ProjectManagerException("Error deleting project version files " + projectId + ":" + version,
                e);
    }
}