use of org.jdbi.v3.core.statement.Query in project tutorials by eugenp.
the class JdbiTest method whenMultipleResults_thenFindOnlyThrows.
@Test
public void whenMultipleResults_thenFindOnlyThrows() {
Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
jdbi.useHandle(handle -> {
handle.execute("create table PROJECT_9 (ID IDENTITY, NAME VARCHAR (50), URL VARCHAR (100))");
handle.execute("INSERT INTO PROJECT_9 (NAME, URL) VALUES ('tutorials', 'github.com/eugenp/tutorials')");
handle.execute("INSERT INTO PROJECT_9 (NAME, URL) VALUES ('REST with Spring', 'github.com/eugenp/REST-With-Spring')");
try {
Query query = handle.createQuery("select * from project_9");
Map<String, Object> onlyResult = query.mapToMap().findOnly();
fail("Exception expected");
} catch (Exception e) {
e.printStackTrace();
}
});
}
use of org.jdbi.v3.core.statement.Query in project tutorials by eugenp.
the class JdbiTest method whenSelectMapToString_thenResultIsString.
@Test
public void whenSelectMapToString_thenResultIsString() {
Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
jdbi.useHandle(handle -> {
handle.execute("create table PROJECT_4 (ID IDENTITY, NAME VARCHAR (50), URL VARCHAR (100))");
handle.execute("INSERT INTO PROJECT_4 (NAME, URL) VALUES ('tutorials', 'github.com/eugenp/tutorials')");
handle.execute("INSERT INTO PROJECT_4 (NAME, URL) VALUES ('REST with Spring', 'github.com/eugenp/REST-With-Spring')");
Query query = handle.createQuery("select name, url from PROJECT_4 order by id");
List<String> list = query.mapTo(String.class).list();
assertEquals("tutorials", list.get(0));
assertEquals("REST with Spring", list.get(1));
});
}
use of org.jdbi.v3.core.statement.Query in project tutorials by eugenp.
the class JdbiTest method whenMultipleResults_thenFindFirstReturnsFirst.
@Test
public void whenMultipleResults_thenFindFirstReturnsFirst() {
Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
jdbi.useHandle(handle -> {
handle.execute("create table PROJECT_7 (ID IDENTITY, NAME VARCHAR (50), URL VARCHAR (100))");
handle.execute("INSERT INTO PROJECT_7 (NAME, URL) VALUES ('tutorials', 'github.com/eugenp/tutorials')");
handle.execute("INSERT INTO PROJECT_7 (NAME, URL) VALUES ('REST with Spring', 'github.com/eugenp/REST-With-Spring')");
Query query = handle.createQuery("select * from project_7 order by id");
Optional<Map<String, Object>> first = query.mapToMap().findFirst();
assertTrue(first.isPresent());
assertEquals("tutorials", first.get().get("name"));
});
}
Aggregations