use of org.apache.commons.dbutils.QueryRunner in project testcontainers-java by testcontainers.
the class OracleJDBCDriverTest method performSimpleTest.
private void performSimpleTest(String jdbcUrl) throws SQLException {
HikariDataSource dataSource = getDataSource(jdbcUrl, 1);
new QueryRunner(dataSource).query("SELECT 1 FROM dual", new ResultSetHandler<Object>() {
@Override
public Object handle(ResultSet rs) throws SQLException {
rs.next();
int resultSetInt = rs.getInt(1);
assertEquals("A basic SELECT query succeeds", 1, resultSetInt);
return true;
}
});
dataSource.close();
}
use of org.apache.commons.dbutils.QueryRunner in project tutorials by eugenp.
the class DbUtilsUnitTest method givenResultHandler_whenExecutingQuery_thenExpectedScalar.
@Test
public void givenResultHandler_whenExecutingQuery_thenExpectedScalar() throws SQLException {
ScalarHandler<Long> scalarHandler = new ScalarHandler<>();
QueryRunner runner = new QueryRunner();
String query = "SELECT COUNT(*) FROM employee";
long count = runner.query(connection, query, scalarHandler);
assertEquals(count, 5);
}
use of org.apache.commons.dbutils.QueryRunner in project tutorials by eugenp.
the class DbUtilsUnitTest method givenResultHandler_whenExecutingQuery_thenEmployeeList.
@Test
public void givenResultHandler_whenExecutingQuery_thenEmployeeList() throws SQLException {
BeanListHandler<Employee> beanListHandler = new BeanListHandler<>(Employee.class);
QueryRunner runner = new QueryRunner();
List<Employee> employeeList = runner.query(connection, "SELECT * FROM employee", beanListHandler);
assertEquals(employeeList.size(), 5);
assertEquals(employeeList.get(0).getFirstName(), "John");
assertEquals(employeeList.get(4).getFirstName(), "Christian");
}
Aggregations