use of org.jdbi.v3.core.statement.Update in project tutorials by eugenp.
the class JdbiTest method whenMultipleParameters_thenReplacement.
@Test
public void whenMultipleParameters_thenReplacement() {
Jdbi jdbi = Jdbi.create("jdbc:hsqldb:mem:testDB", "sa", "");
jdbi.useHandle(handle -> {
handle.execute("create table PROJECT_11 (ID IDENTITY, NAME VARCHAR (50), URL VARCHAR (100))");
Update update = handle.createUpdate("INSERT INTO PROJECT_11 (NAME, URL) VALUES (:name, :url)");
Map<String, String> params = new HashMap<>();
params.put("name", "REST with Spring");
params.put("url", "github.com/eugenp/REST-With-Spring");
update.bindMap(params);
int rows = update.execute();
assertEquals(1, rows);
List<Map<String, Object>> list = handle.select("SELECT * FROM PROJECT_11").mapToMap().list();
assertEquals(1, list.size());
class Params {
private String name;
private String url;
public Params(String name, String url) {
this.name = name;
this.url = url;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
update.bindBean(new Params("tutorials", "github.com/eugenp/tutorials"));
rows = update.execute();
assertEquals(1, rows);
list = handle.select("SELECT * FROM PROJECT_11").mapToMap().list();
assertEquals(2, list.size());
});
}
Aggregations