List of usage examples for org.apache.commons.dbutils QueryRunner update
public int update(String sql) throws SQLException
From source file:azkaban.database.AzkabanDatabaseUpdaterTest.java
private static void clearMySQLTestDb() throws SQLException { Props props = new Props(); props.put("database.type", "mysql"); props.put("mysql.host", "localhost"); props.put("mysql.port", "3306"); props.put("mysql.database", ""); props.put("mysql.user", "root"); props.put("mysql.password", ""); props.put("mysql.numconnections", 10); DataSource datasource = DataSourceUtils.getDataSource(props); QueryRunner runner = new QueryRunner(datasource); try {/* w w w .j a v a 2 s .c om*/ runner.update("drop database azkabanunittest"); } catch (SQLException e) { } runner.update("create database azkabanunittest"); }
From source file:azkaban.database.AzkabanDatabaseSetupTest.java
private static void clearMySQLTestDB() throws SQLException { Props props = new Props(); props.put("database.type", "mysql"); props.put("mysql.host", "localhost"); props.put("mysql.port", "3306"); props.put("mysql.database", ""); props.put("mysql.user", "root"); props.put("mysql.password", ""); props.put("mysql.numconnections", 10); DataSource datasource = DataSourceUtils.getDataSource(props); QueryRunner runner = new QueryRunner(datasource); try {// ww w. ja v a2s . c om runner.update("drop database azkabanunittest"); } catch (SQLException e) { } runner.update("create database azkabanunittest"); }
From source file:azkaban.database.DataSourceUtils.java
public static void testConnection(DataSource ds) throws SQLException { QueryRunner runner = new QueryRunner(ds); runner.update("SHOW TABLES"); }
From source file:jongo.demo.Demo.java
private static void destroyDemoDatabase(final DatabaseConfiguration dbcfg) { final String database = dbcfg.getDatabase(); QueryRunner run = new QueryRunner(JDBCConnectionFactory.getDataSource(dbcfg)); l.info("Destroying Demo Tables in database " + database); try {//from w ww .java 2s. c o m run.update("DROP FUNCTION simpleStoredProcedure"); run.update("DROP PROCEDURE insert_comment"); run.update("DROP PROCEDURE get_year_sales"); run.update("DROP VIEW MAKER_STATS_2010"); run.update("DROP TABLE maker_stats"); run.update("DROP TABLE sales_stats"); run.update("DROP TABLE comments"); run.update("DROP TABLE pictures"); run.update("DROP TABLE car"); run.update("DROP TABLE users"); run.update("DROP TABLE maker"); run.update("DROP TABLE empty"); } catch (SQLException ex) { l.error("Failed to destroy demo tables " + ex.getMessage()); } finally { try { run.getDataSource().getConnection().close(); } catch (SQLException ex) { l.error("Failed to close demo database " + ex.getMessage()); } } }
From source file:jongo.jdbc.JDBCExecutor.java
/** * Executes the given {@link jongo.sql.Insert} object * @param insert a {@link jongo.sql.Insert} instance * @return number of records inserted//from w w w . j a va 2s. co m * @throws SQLException from the QueryRunner * @see org.apache.commons.dbutils.QueryRunner */ public static int insert(final Insert insert) throws SQLException { l.debug(insert.toString()); DatabaseConfiguration dbconf = conf.getDatabaseConfiguration(insert.getTable().getDatabase()); QueryRunner run = JDBCConnectionFactory.getQueryRunner(dbconf); Dialect dialect = DialectFactory.getDialect(dbconf); try { int inserted; if (insert.getColumns().isEmpty()) inserted = run.update(dialect.toStatementString(insert)); else inserted = run.update(dialect.toStatementString(insert), JongoUtils.parseValues(insert.getValues())); l.debug("Inserted " + inserted + " records."); return inserted; } catch (SQLException ex) { l.debug(ex.getMessage()); throw ex; } }
From source file:iudex.da.Helper.java
@Before public void clear() throws SQLException { QueryRunner runner = new QueryRunner(_dataSource); runner.update("DELETE from urls;"); }
From source file:com.fluke.database.dataservice.EquityDao.java
public void changeGroup(String equity, String group) throws SQLException { String sql = "update ticker set grade ='" + group + "' where equity='" + equity + "'"; QueryRunner run = new QueryRunner(DatabaseProperty.getDataSource()); run.update(sql); }
From source file:com.rhino.data.db.EquityDao.java
public void changeGroup(String equity, String group) throws SQLException { String sql = "update ticker set grade ='" + group + "' where equity='" + equity + "'"; QueryRunner run = new QueryRunner(DataSourceFactory.getDataSource()); run.update(sql); }
From source file:com.gs.obevo.dbmetadata.impl.dialects.PostgresqlDbMetadataManagerIT.java
@Override protected void setCurrentSchema(QueryRunner jdbc) throws Exception { jdbc.update("SET search_path TO " + getSchemaName()); }
From source file:io.stallion.dataAccess.db.postgres.PostgresTickets.java
public void createSequence() { QueryRunner q = db.newQuery(); try {//from w w w . j a v a 2 s .c o m q.update("CREATE SEQUENCE stallion_tickets_seq INCREMENT BY 300 MINVALUE 100000;"); } catch (Exception e) { Log.info("Sequence already exists"); } }