Search in sources :

Example 56 with Statement

use of java.sql.Statement in project camel by apache.

the class MyBatisTestSupport method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    // lets create the table...
    Connection connection = createConnection();
    Statement statement = connection.createStatement();
    statement.execute(createStatement());
    connection.commit();
    statement.close();
    connection.close();
    if (createTestData()) {
        Account account1 = new Account();
        account1.setId(123);
        account1.setFirstName("James");
        account1.setLastName("Strachan");
        account1.setEmailAddress("TryGuessing@gmail.com");
        Account account2 = new Account();
        account2.setId(456);
        account2.setFirstName("Claus");
        account2.setLastName("Ibsen");
        account2.setEmailAddress("Noname@gmail.com");
        template.sendBody("mybatis:insertAccount?statementType=Insert", new Account[] { account1, account2 });
    }
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) Before(org.junit.Before)

Example 57 with Statement

use of java.sql.Statement in project databus by linkedin.

the class BootstrapConn method executeDDL.

public void executeDDL(String sql) throws SQLException {
    Statement stmt = null;
    LOG.info("Executing DDL command :" + sql);
    try {
        stmt = _bootstrapConn.createStatement();
        int rs = stmt.executeUpdate(sql);
        DBHelper.commit(_bootstrapConn);
        LOG.info("Executed Commmand (" + sql + ") with result " + rs);
    } catch (SQLException s) {
        DBHelper.rollback(_bootstrapConn);
    } finally {
        DBHelper.close(stmt);
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement)

Example 58 with Statement

use of java.sql.Statement in project databus by linkedin.

the class BootstrapConn method executeQueryAndGetLong.

public long executeQueryAndGetLong(String query, long defaultVal) throws SQLException {
    Statement stmt = null;
    Connection conn = getDBConn();
    ResultSet rs = null;
    long res = defaultVal;
    try {
        stmt = conn.createStatement();
        rs = stmt.executeQuery(query);
        if (rs.next()) {
            res = rs.getLong(1);
        }
    } finally {
        DBHelper.close(rs, stmt, null);
    }
    return res;
}
Also used : Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 59 with Statement

use of java.sql.Statement in project databus by linkedin.

the class BootstrapDBCleanerQueryExecutor method getLastEventinLog.

private BootstrapDBRow getLastEventinLog(BootstrapLogInfo logInfo, DbusEventFactory eventFactory) throws SQLException {
    Statement stmt = null;
    ResultSet rs = null;
    long id = -1;
    long scn = -1;
    String key = null;
    DbusEvent event = null;
    try {
        String tableName = logInfo.getLogTable();
        StringBuilder sql = new StringBuilder();
        sql.append("select id, srckey, scn, val from ");
        sql.append(tableName);
        sql.append(" where id = ( select max(id) from ");
        sql.append(tableName);
        sql.append(" )");
        stmt = _conn.createStatement();
        rs = stmt.executeQuery(sql.toString());
        if (rs.next()) {
            int i = 1;
            id = rs.getLong(i++);
            String srcKey = rs.getString(i++);
            scn = rs.getLong(i++);
            ByteBuffer tmpBuffer = ByteBuffer.wrap(rs.getBytes(i));
            LOG.info("BUFFER SIZE:" + tmpBuffer.limit());
            event = eventFactory.createReadOnlyDbusEventFromBuffer(tmpBuffer, tmpBuffer.position());
            LOG.info("Last Row for log (" + logInfo + ") - ID :" + id + ", srcKey :" + srcKey + ", SCN :" + scn + ", Event :" + event.toString());
        } else {
            LOG.error("No ResultSet for query :" + sql.toString());
        }
    } finally {
        DBHelper.close(rs, stmt, null);
    }
    return new BootstrapDBRow(id, key, scn, event);
}
Also used : DbusEvent(com.linkedin.databus.core.DbusEvent) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ByteBuffer(java.nio.ByteBuffer)

Example 60 with Statement

use of java.sql.Statement in project databus by linkedin.

the class BootstrapDBMetaDataDAO method createDB.

public static void createDB(String dbName, String dbUsername, String dbPassword, String dbHostname) throws SQLException {
    String dbSql = "CREATE DATABASE if not exists " + dbName;
    BootstrapConn bConn = new BootstrapConn();
    Statement stmt = null;
    try {
        LOG.info("Creating new db using SQL :" + dbSql);
        try {
            bConn.initBootstrapConn(false, dbUsername, dbPassword, dbHostname, null);
        } catch (InstantiationException e) {
            LOG.error("Got instantiation error while creating new bootstrapDB :", e);
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            LOG.error("Got illegal access error while creating new bootstrapDB :", e);
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            LOG.error("Got class-not-found error while creating new bootstrapDB :", e);
            throw new RuntimeException(e);
        }
        stmt = bConn.getDBConn().createStatement();
        int ret = stmt.executeUpdate(dbSql);
        LOG.info("Create DB returned :" + ret);
    } catch (SQLException sqlEx) {
        LOG.error("Got error while creating new bootstrapDB :", sqlEx);
        throw sqlEx;
    } finally {
        DBHelper.close(stmt);
        bConn.close();
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement)

Aggregations

Statement (java.sql.Statement)3054 Connection (java.sql.Connection)1634 ResultSet (java.sql.ResultSet)1631 SQLException (java.sql.SQLException)1529 PreparedStatement (java.sql.PreparedStatement)1329 Test (org.junit.Test)570 ArrayList (java.util.ArrayList)323 CallableStatement (java.sql.CallableStatement)135 ResultSetMetaData (java.sql.ResultSetMetaData)127 IOException (java.io.IOException)121 Properties (java.util.Properties)114 HashMap (java.util.HashMap)83 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)81 DruidPooledStatement (com.alibaba.druid.pool.DruidPooledStatement)71 StringPlus (mom.trd.opentheso.bdd.tools.StringPlus)63 DataSource (javax.sql.DataSource)62 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)61 Vector (java.util.Vector)61 DatabaseMetaData (java.sql.DatabaseMetaData)53 KeyValue (org.vcell.util.document.KeyValue)49