use of org.jdbi.v3.core.statement.PreparedBatch in project jdbi by jdbi.
the class TestBatch method testEmptyBatchThrows.
@Test(expected = IllegalStateException.class)
public void testEmptyBatchThrows() throws Exception {
try (Handle h = dbRule.openHandle()) {
final PreparedBatch b = h.prepareBatch("insert into something (id, name) values (?, ?)");
// No parameters written yet
b.add();
}
}
use of org.jdbi.v3.core.statement.PreparedBatch in project jdbi by jdbi.
the class TestTimingCollector method testRawSql.
@Test
public void testRawSql() {
db.useHandle(h -> {
PreparedBatch batch = h.prepareBatch("insert into something (id, name) values (?, ?)");
batch.add(1, "Mary");
batch.add(2, "David");
batch.add(3, "Kate");
batch.execute();
});
List<String> names = db.withHandle(h -> h.createQuery("select name from something order by name").mapTo(String.class).list());
assertThat(names).containsExactly("David", "Kate", "Mary");
assertThat(timingCollector.statementNames).containsOnly("sql.raw.insert into something (id, name) values (?, ?)", "sql.raw.select name from something order by name");
}
Aggregations