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 });
}
}
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);
}
}
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;
}
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);
}
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();
}
}
Aggregations