List of usage examples for org.apache.commons.dbutils QueryRunner QueryRunner
public QueryRunner()
From source file:azkaban.scheduler.JdbcScheduleLoader.java
@Override public List<Schedule> loadSchedules() throws ScheduleManagerException { logger.info("Loading all schedules from db."); Connection connection = getConnection(); QueryRunner runner = new QueryRunner(); ResultSetHandler<List<Schedule>> handler = new ScheduleResultHandler(); List<Schedule> schedules; try {// w ww . ja v a 2 s . c om schedules = runner.query(connection, SELECT_ALL_SCHEDULES, handler); } catch (SQLException e) { logger.error(SELECT_ALL_SCHEDULES + " failed."); DbUtils.closeQuietly(connection); throw new ScheduleManagerException("Loading schedules from db failed. ", e); } finally { DbUtils.closeQuietly(connection); } logger.info("Now trying to update the schedules"); // filter the schedules for (Schedule sched : schedules) { if (!sched.updateTime()) { logger.info("Schedule " + sched.getScheduleName() + " was scheduled before azkaban start, skipping it."); schedules.remove(sched); removeSchedule(sched); } else { logger.info("Recurring schedule, need to update next exec time"); try { updateNextExecTime(sched); } catch (Exception e) { e.printStackTrace(); throw new ScheduleManagerException("Update next execution time failed.", e); } logger.info("Schedule " + sched.getScheduleName() + " loaded and updated."); } } logger.info("Loaded " + schedules.size() + " schedules."); return schedules; }
From source file:azkaban.trigger.JdbcTriggerLoaderTest.java
public void setupDB() { DataSource dataSource = DataSourceUtils.getMySQLDataSource(host, port, database, user, password, numConnections);/* ww w . j av a 2 s. com*/ testDBExists = true; Connection connection = null; try { connection = dataSource.getConnection(); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } CountHandler countHandler = new CountHandler(); QueryRunner runner = new QueryRunner(); try { runner.query(connection, "SELECT COUNT(1) FROM triggers", countHandler); } catch (SQLException e) { e.printStackTrace(); testDBExists = false; DbUtils.closeQuietly(connection); return; } DbUtils.closeQuietly(connection); clearDB(); }
From source file:com.netradius.hibernate.support.HibernateUtil.java
@SuppressWarnings("unchecked") public static <T> T query(String query, ResultSetHandler<T> handler, Object... params) throws SQLException { final Connection con = getConnection(); try {// www. ja v a 2s .c om return (T) new QueryRunner().query(con, query, handler, params); } finally { DbUtils.close(con); } }
From source file:hermes.store.schema.DefaultJDBCAdapter.java
public void remove(Connection connection, String storeId) throws SQLException { final QueryRunner runner = new QueryRunner(); for (final String statment : statements.getRemoveStoreStatements()) { runner.update(connection, statment, new Object[] { storeId }); }/*from w w w . j a v a 2 s .c o m*/ }
From source file:it.attocchi.db.DbUtilsConnector.java
public <T> T executeSingle(boolean keepConnOpen, String aQuery, Class<T> clazz, Object... params) throws Exception { T result = null;//from w w w .j ava2 s . co m // No DataSource so we must handle Connections manually QueryRunner run = new QueryRunner(); try { logger.debug(aQuery); result = run.query(getConnection(), aQuery, getResultSetHandlerSingle(clazz), params); } catch (Exception ex) { logger.error("Error executeSingle", ex); } finally { if (!keepConnOpen) close(); } return result; }
From source file:net.orpiske.ssps.common.db.AbstractDao.java
/** * Runs an UPDATE/INSERT/DELETE statement * @param query The query (statement) to run * @param args The arguments to the query * @return The number of affected rows/*from ww w. j av a2s . c om*/ * @throws SQLException If unable to perform the operation */ protected int runQueryCount(String query, Object... args) throws SQLException { Connection conn = databaseManager.getConnection(); QueryRunner run = new QueryRunner(); CountRsHandler rs = new CountRsHandler(); Integer count = run.query(conn, query, rs, args); return count.intValue(); }
From source file:dbutils.DbUtilsTemplate.java
/** * sql?,?????/* ww w .j ava 2 s.c o m*/ * * @param sql sql? * @param params ? * @return ?? */ public int update(String sql, Object[] params) throws SQLException { queryRunner = new QueryRunner(); int affectedRows = 0; Connection conn = null; try { conn = dataSource.getConnection(); if (params == null) { affectedRows = queryRunner.update(conn, sql); } else { affectedRows = queryRunner.update(conn, sql, params); } } catch (SQLException e) { LOG.error("Error occured while attempting to update data", e); if (conn != null) { conn.rollback(); } throw e; } finally { if (conn != null) DbUtils.commitAndClose(conn); } return affectedRows; }
From source file:com.gs.obevo.dbmetadata.impl.dialects.Db2MetadataDialect.java
@Override public ImmutableCollection<DaSequence> searchSequences(final DaSchema schema, Connection conn) throws SQLException { QueryRunner query = new QueryRunner(); // SEQTYPE <> 'I' is for identity columns; we don't want that when pulling user defined sequences ImmutableList<Map<String, Object>> maps = ListAdapter .adapt(query//from w w w. j a v a 2 s .c o m .query(conn, "select SEQNAME SEQUENCE_NAME from syscat.SEQUENCES\n" + "where SEQSCHEMA = '" + schema.getName() + "' AND SEQTYPE <> 'I'\n", new MapListHandler())) .toImmutable(); return maps.collect(new Function<Map<String, Object>, DaSequence>() { @Override public DaSequence valueOf(Map<String, Object> map) { return new DaSequenceImpl((String) map.get("SEQUENCE_NAME"), schema); } }); }
From source file:de.unibremen.informatik.tdki.combo.data.DBLayout.java
public DBLayout(boolean useInsert, Connection connection) { this.useInsert = useInsert; this.connection = connection; qRunner = new QueryRunner(); }
From source file:dbutils.ExampleJDBC.java
/** * MapListHandler ResultSet??ListListMap *//*w w w . j a va 2s. c o m*/ public static void getMapListData() { Connection conn = getConnection(); QueryRunner qr = new QueryRunner(); try { List results = (List) qr.query(conn, "SELECT id, name, gender, age, team_id FROM test_student", new MapListHandler()); for (Object result : results) { Map map = (Map) result; System.out.println( "id=" + map.get("id") + " name=" + map.get("name") + " gender=" + map.get("gender")); } } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } }