Search in sources :

Example 6 with PreparedBatch

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();
    }
}
Also used : Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 7 with PreparedBatch

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");
}
Also used : PreparedBatch(org.jdbi.v3.core.statement.PreparedBatch) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 Handle (org.jdbi.v3.core.Handle)4 PreparedBatch (org.jdbi.v3.core.statement.PreparedBatch)4 Something (org.jdbi.v3.core.Something)2 NoSuchElementException (java.util.NoSuchElementException)1 Jdbi (org.jdbi.v3.core.Jdbi)1 StatementContext (org.jdbi.v3.core.statement.StatementContext)1