List of usage examples for org.apache.commons.dbutils.handlers ColumnListHandler ColumnListHandler
public ColumnListHandler()
From source file:com.rhino.data.db.EquityDao.java
public List<String> getAllEquity() throws SQLException { String sql = "select distinct equity from EOD"; QueryRunner run = new QueryRunner(DataSourceFactory.getDataSource()); ResultSetHandler rsh = new ColumnListHandler(); return (List<String>) run.query(sql, rsh); }
From source file:com.fluke.database.dataservice.EquityDao.java
public List<String> getAllEquity() throws SQLException { String sql = "select distinct equity from EOD"; QueryRunner run = new QueryRunner(DatabaseProperty.getDataSource()); ResultSetHandler rsh = new ColumnListHandler(); return (List<String>) run.query(sql, rsh); }
From source file:com.rhino.data.db.EquityDao.java
public List<String> getAllEquity(String grade) throws SQLException { String sql = "select distinct equity from EOD where grade='" + grade + "'"; QueryRunner run = new QueryRunner(DataSourceFactory.getDataSource()); ResultSetHandler rsh = new ColumnListHandler(); return (List<String>) run.query(sql, rsh); }
From source file:com.fluke.database.dataservice.EquityDao.java
public List<String> getAllEquity(String grade) throws SQLException { String sql = "select distinct equity from EOD"; QueryRunner run = new QueryRunner(DatabaseProperty.getDataSource()); ResultSetHandler rsh = new ColumnListHandler(); return (List<String>) run.query(sql, rsh); }
From source file:ch.vorburger.mariadb4j.MariaDB4jSampleTutorialTest.java
@Test public void testEmbeddedMariaDB4j() throws Exception { DB db = DB.newEmbeddedDB(3308);//from ww w .j av a2 s . c om db.start(); Connection conn = null; try { conn = db.getConnection(); QueryRunner qr = new QueryRunner(); // Should be able to create a new table qr.update(conn, "CREATE TABLE hello(world VARCHAR(100))"); // Should be able to insert into a table qr.update(conn, "INSERT INTO hello VALUES ('Hello, world')"); // Should be able to select from a table List<String> results = qr.query(conn, "SELECT * FROM hello", new ColumnListHandler<String>()); Assert.assertEquals(1, results.size()); Assert.assertEquals("Hello, world", results.get(0)); // Should be able to source a SQL file db.source("ch/vorburger/mariadb4j/testSourceFile.sql"); results = qr.query(conn, "SELECT * FROM hello", new ColumnListHandler<String>()); Assert.assertEquals(3, results.size()); Assert.assertEquals("Hello, world", results.get(0)); Assert.assertEquals("Bonjour, monde", results.get(1)); Assert.assertEquals("Hola, mundo", results.get(2)); } finally { DbUtils.closeQuietly(conn); } }
From source file:ch.vorburger.mariadb4j.tests.MariaDB4jSampleTutorialTest.java
@Test public void testEmbeddedMariaDB4j() throws Exception { DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); config.setPort(0); // 0 => autom. detect free port DB db = DB.newEmbeddedDB(config.build()); db.start();// w w w . j a va 2 s. c o m String dbName = "mariaDB4jTest"; // or just "test" if (!dbName.equals("test")) { // mysqld out-of-the-box already has a DB named "test" // in case we need another DB, here's how to create it first db.createDB(dbName); } Connection conn = null; try { conn = DriverManager.getConnection(config.getURL(dbName), "root", ""); QueryRunner qr = new QueryRunner(); // Should be able to create a new table qr.update(conn, "CREATE TABLE hello(world VARCHAR(100))"); // Should be able to insert into a table qr.update(conn, "INSERT INTO hello VALUES ('Hello, world')"); // Should be able to select from a table List<String> results = qr.query(conn, "SELECT * FROM hello", new ColumnListHandler<String>()); Assert.assertEquals(1, results.size()); Assert.assertEquals("Hello, world", results.get(0)); // Should be able to source a SQL file db.source("ch/vorburger/mariadb4j/testSourceFile.sql", "root", null, dbName); results = qr.query(conn, "SELECT * FROM hello", new ColumnListHandler<String>()); Assert.assertEquals(3, results.size()); Assert.assertEquals("Hello, world", results.get(0)); Assert.assertEquals("Bonjour, monde", results.get(1)); Assert.assertEquals("Hola, mundo", results.get(2)); } finally { DbUtils.closeQuietly(conn); } }
From source file:com.gs.obevo.db.impl.platforms.sybaseiq.IqPostDeployAction.java
@Override public void value(DbEnvironment env) { LOG.info("Recompiling views for Sybase IQ..."); for (int i = 0; i < 2; i++) { for (final PhysicalSchema physicalSchema : env.getPhysicalSchemas()) { dataSourceForEditsFactory.executeWithinContext(physicalSchema, new Procedure<Connection>() { @Override/*from w w w . j a va 2 s . co m*/ public void value(Connection conn) { JdbcHelper jdbcTemplate = dataSourceForEditsFactory.getJdbcTemplate(); List<String> viewRecompiles = jdbcTemplate.query(conn, "SELECT 'ALTER VIEW ' || vcreator || '.' || viewname || ' RECOMPILE' FROM sys.SYSVIEWS WHERE lcase(vcreator) = '" + physicalSchema.getPhysicalName() + "'", new ColumnListHandler<String>()); for (String viewRecompile : viewRecompiles) { try { jdbcTemplate.update(conn, viewRecompile); } catch (DataAccessException e) { LOG.info( "Could not recompile query [{}] - skipping as we rely on executing a couple times to fix all views. Message was: {}", viewRecompile, e.getMessage()); } } } }); } } }
From source file:com.gs.obevo.db.impl.platforms.hsql.HsqlEnvironmentSetupInfra.java
@Override public void setupEnvInfra(boolean failOnSetupException) { JdbcHelper jdbc = new JdbcHelper(); Connection conn = null;//from w w w. java2s . c om try { conn = ds.getConnection(); for (PhysicalSchema schema : env.getPhysicalSchemas()) { if (!isSchemaAlreadySetup(schema)) { LOG.info("Creating schema {}", schema.getPhysicalName()); jdbc.update(conn, "CREATE SCHEMA " + schema.getPhysicalName() + " AUTHORIZATION DBA"); } } ImmutableSet<String> existingGroups = Sets.immutable.withAll(jdbc.query(conn, "select ROLE_NAME from INFORMATION_SCHEMA.APPLICABLE_ROLES", new ColumnListHandler<String>())) .collect(StringFunctions.toLowerCase()); for (Group group : env.getGroups()) { if (!groupAlreadySetup(group, existingGroups)) { jdbc.update(conn, "CREATE ROLE " + group.getName()); } } ImmutableSet<String> existingUsers = Sets.immutable.withAll(jdbc.query(conn, "select USER_NAME from INFORMATION_SCHEMA.SYSTEM_USERS", new ColumnListHandler<String>())) .collect(StringFunctions.toLowerCase()); for (User user : env.getUsers()) { if (!isUserAlreadySetup(existingUsers, user)) { StringBuilder sb = new StringBuilder(); String password = user.getPassword() != null ? user.getPassword() : "dummypwd"; sb.append("CREATE USER \"").append(user.getName()).append("\""); sb.append(" PASSWORD \"").append(password).append("\""); if (user.isAdmin()) { sb.append(" ADMIN"); } jdbc.update(conn, sb.toString()); } } } catch (SQLException e) { throw new RuntimeException(e); } finally { DbUtils.closeQuietly(conn); } }
From source file:com.gs.obevo.db.impl.platforms.db2.Db2EnvironmentInfraSetup.java
@Override public void setupEnvInfra(boolean failOnSetupException) { LOG.info("Verifying existence of DB2 groups prior to deployment"); ImmutableSet<String> existingGroups; Connection conn = null;/* www.ja v a 2 s.co m*/ try { conn = ds.getConnection(); existingGroups = Sets.immutable .withAll(jdbc.query(conn, "select ROLENAME from sysibm.SYSROLES", new ColumnListHandler<String>())) .newWithAll(jdbc.query(conn, "select GRANTEE from sysibm.SYSDBAUTH", new ColumnListHandler<String>())) .collect(StringFunctions.trim()); // db2 sometimes has whitespace in its return results that needs trimming } catch (Exception e) { if (failOnSetupException) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } throw new RuntimeException(e); } else { LOG.warn("Group validation query failed; continuing w/ deployment per configuration", e); deployMetricsCollector.addMetric(DeployMetrics.WARNINGS_PREFIX + ".db2GroupValidationQueryFailure", true); return; } } finally { DbUtils.closeQuietly(conn); } LOG.info("Groups from DB: {}", existingGroups); ImmutableList<String> groupNames = env.getGroups().collect(Group.TO_NAME); LOG.info("Groups from system-config: {}", groupNames); // Do difference comparison in a case insensitive manner (convert all to lowercase) ImmutableList<String> missingGroups = groupNames.select(Predicates.attributeNotIn( StringFunctions.toLowerCase(), existingGroups.collect(StringFunctions.toLowerCase()))); if (missingGroups.notEmpty()) { String errorMessage = "The following groups were not found in your DB2 server (checked against sysibm.SYSROLES and sysibm.SYSDBAUTH): " + missingGroups; if (failOnSetupException) { throw new IllegalArgumentException(errorMessage); } else { LOG.warn(errorMessage); LOG.warn("Will proceed with deployment as you have configured this to just be a warning"); deployMetricsCollector.addMetric(DeployMetrics.WARNINGS_PREFIX + ".db2GroupsInConfigButNotInDb", errorMessage); } } }
From source file:com.fluke.data.processor.ReatimeDBReader.java
public List<String> getAllEquity() throws SQLException { String sql = "select distinct equity from realtime"; QueryRunner run = new QueryRunner(DatabaseProperty.getDataSource()); ResultSetHandler rsh = new ColumnListHandler(); return (List<String>) run.query(sql, rsh); }