本文整理了Java中org.jdbi.v3.core.Handle.execute()
方法的一些代码示例,展示了Handle.execute()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Handle.execute()
方法的具体详情如下:
包路径:org.jdbi.v3.core.Handle
类名称:Handle
方法名:execute
[英]Execute a SQL statement, and return the number of rows affected by the statement.
[中]执行SQL语句,并返回受该语句影响的行数。
代码示例来源:origin: jdbi/jdbi
@Test
public void testPositionalConvenienceInsert() {
int count = h.execute("insert into something (id, name) values (?, ?)", 1, "eric");
assertThat(count).isEqualTo(1);
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testDurationTooPrecise() {
assertThatThrownBy(() -> handle.execute("insert into intervals(id, foo) values(?, ?)", 12, Duration.ofNanos(100)))
.isInstanceOf(IllegalArgumentException.class);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void singleValue() {
handle.execute("CREATE TABLE stuff (id INT, name VARCHAR)");
handle.execute("INSERT INTO stuff (id, name) VALUES (1, 'abc,123,xyz')");
handle.execute("INSERT INTO stuff (id, name) VALUES (2, 'foo,bar,baz')");
SingleValueDao singleValueDao = handle.attach(SingleValueDao.class);
assertThat(singleValueDao.multipleRows())
.containsExactly("zyx,321,cba", "zab,rab,oof");
assertThat(singleValueDao.singleRow())
.containsExactly("cba", "321", "zyx");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testFindNamesConditionalExecutionWithNullValue() {
handle.execute("insert into something (id, name) values (6, 'Jack')");
handle.execute("insert into something (id, name) values (7, 'Wolf')");
List<String> s = handle.attach(Wombat.class).findNamesByDefinedIdsOrAll(null);
assertThat(s).containsExactly("Jack", "Wolf");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testConvenienceMethod() {
h.execute("insert into something (id, name) values (1, 'eric')");
h.execute("insert into something (id, name) values (2, 'brian')");
List<Map<String, Object>> r = h.select("select * from something order by id").mapToMap().list();
assertThat(r).hasSize(2);
assertThat(r.get(0).get("name")).isEqualTo("eric");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testConvenienceMethodWithParam() {
h.execute("insert into something (id, name) values (1, 'eric')");
h.execute("insert into something (id, name) values (2, 'brian')");
List<Map<String, Object>> r = h.select("select * from something where id = ?", 1).mapToMap().list();
assertThat(r).hasSize(1);
assertThat(r.get(0).get("name")).isEqualTo("eric");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testMapMapperOrdering() {
h.execute("insert into something (id, name) values (?, ?)", 1, "hello");
h.execute("insert into something (id, name) values (?, ?)", 2, "world");
List<Map<String, Object>> rs = h.createQuery("select id, name from something")
.mapToMap()
.list();
assertThat(rs).hasSize(2);
assertThat(rs).hasOnlyElementsOfType(LinkedHashMap.class);
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testObtainHandleInCallback() {
Jdbi db = Jdbi.create("jdbc:h2:mem:" + UUID.randomUUID());
db.useHandle(handle -> handle.execute("create table silly (id int)"));
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testBindMap() {
handle.execute("insert into something (id, name) values (1, 'Alice')");
dao.update(1, singletonMap("name", "Alicia"));
assertThat(dao.get(1).getName()).isEqualTo("Alicia");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testExceptionAbortsTransaction() {
assertThatThrownBy(() ->
h.inTransaction(handle -> {
handle.execute("insert into something (id, name) values (?, ?)", 0, "Keith");
throw new IOException();
}))
.isInstanceOf(IOException.class);
List<Something> r = h.createQuery("select * from something").mapToBean(Something.class).list();
assertThat(r).isEmpty();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testSetPositionalString() {
h.execute("insert into something (id, name) values (1, 'eric')");
h.execute("insert into something (id, name) values (2, 'brian')");
Something eric = h.createQuery("select * from something where name = ?")
.bind(0, "eric")
.mapToBean(Something.class)
.list()
.get(0);
assertThat(eric.getId()).isEqualTo(1);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testFindBeanWithBind() {
handle.execute("insert into something (id, name) values (6, 'Martin Freeman')");
Something s = handle.attach(Wombat.class).findByBoundId(6L);
assertThat(s.getName()).isEqualTo("Martin Freeman");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testFindBeanWithDefine() {
handle.execute("insert into something (id, name) values (6, 'Peter Jackson')");
Something s = handle.attach(Wombat.class).findByDefinedId(6L);
assertThat(s.getName()).isEqualTo("Peter Jackson");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testBam() {
handle.execute("insert into something (id, name) values (6, 'Martin')");
Something s = handle.attach(Wombat.class).findById(6L);
assertThat(s.getName()).isEqualTo("Martin");
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testMappingExampleChainedIterator3() {
try (Handle h = dbRule.openHandle()) {
h.execute("insert into something (id, name) values (1, 'Brian')");
h.execute("insert into something (id, name) values (2, 'Keith')");
ResultIterable<String> names = h.createQuery("select name from something order by id").mapTo(String.class);
assertThat(names.iterator()).containsExactly("Brian", "Keith");
}
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testTemplateEngineThrowsError() {
assertThatThrownBy(() -> h.setTemplateEngine(new BoomEngine()).inTransaction(h2 -> h2.execute("select 1")))
.isOfAnyClassIn(Error.class)
.hasMessage("boom");
assertThat(h.isInTransaction()).isFalse();
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testUnusedBindingWithOutParameter() {
h.execute("CREATE ALIAS TO_DEGREES FOR \"java.lang.Math.toDegrees\"");
Call call = h.createCall("? = CALL TO_DEGREES(?)")
.registerOutParameter(0, Types.DOUBLE)
.bind(1, 100.0d)
.bind(2, "foo");
assertThatThrownBy(call::invoke).isInstanceOf(UnableToCreateStatementException.class);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void localDateTime() {
LocalDateTime d = LocalDateTime.now();
h.execute("insert into stuff(ts) values (?)", d);
assertThat(h.createQuery("select ts from stuff").mapTo(LocalDateTime.class).findOnly()).isEqualTo(d);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testWritesViaFluentApi() {
handle.execute("insert into intervals(id, foo) values(?, ?)", 6, testPeriod);
final Period p = handle.createQuery("select foo from intervals where id=?")
.bind(0, 6)
.mapTo(Period.class)
.findOnly();
assertThat(p).isEqualTo(testPeriod);
}
代码示例来源:origin: jdbi/jdbi
@Test
public void testPreparedBatchException() {
h.execute(CREATE);
Throwable e = catchThrowable(h.prepareBatch(INSERT_PREPARED).bindByType(0, null, Integer.class)::execute);
assertThat(logger.getRawSql()).containsExactly(CREATE, CREATE, INSERT_PREPARED, INSERT_PREPARED);
assertThat(logger.getTimings()).hasSize(2).allMatch(IS_POSITIVE);
assertThat(logger.getExceptions()).containsExactly((SQLException) e.getCause());
}
内容来源于网络,如有侵权,请联系作者删除!