Search in sources :

Example 1 with OutParameters

use of org.jdbi.v3.core.statement.OutParameters in project jdbi by jdbi.

the class TestOutParameterAnnotation method testOutParameter.

@Test
public void testOutParameter() {
    MyDao myDao = db.onDemand(MyDao.class);
    OutParameters outParameters = myDao.callStoredProc();
    assertThat(outParameters.getInt("outparam")).isEqualTo(100);
}
Also used : OutParameters(org.jdbi.v3.core.statement.OutParameters) Test(org.junit.Test)

Example 2 with OutParameters

use of org.jdbi.v3.core.statement.OutParameters in project jdbi by jdbi.

the class CallTest method testCall.

@Test
public void testCall() {
    Handle handle = db.getHandle();
    handle.execute(findSqlOnClasspath("create_stored_proc_add"));
    // tag::invokeProcedure[]
    OutParameters result = handle.createCall(// <1>
    "{:sum = call add(:a, :b)}").bind("a", // <2>
    13).bind("b", // <2>
    9).registerOutParameter("sum", // <3> <4>
    Types.INTEGER).invoke();
    // end::invokeProcedure[]
    // tag::getOutParameters[]
    int sum = result.getInt("sum");
    // end::getOutParameters[]
    assertThat(sum).isEqualTo(22);
}
Also used : OutParameters(org.jdbi.v3.core.statement.OutParameters) Handle(org.jdbi.v3.core.Handle) Test(org.junit.Test)

Example 3 with OutParameters

use of org.jdbi.v3.core.statement.OutParameters in project jdbi by jdbi.

the class TestSqlCall method testFoo.

@Test
public void testFoo() throws Exception {
    Dao dao = handle.attach(Dao.class);
    // OutParameters out = handle.createCall(":num = call stored_insert(:id, :name)")
    // .bind("id", 1)
    // .bind("name", "Jeff")
    // .registerOutParameter("num", Types.INTEGER)
    // .invoke();
    dao.insert(1, "Jeff");
    assertThat(handle.attach(Dao.class).findById(1)).isEqualTo(new Something(1, "Jeff"));
}
Also used : Something(org.jdbi.v3.core.Something) Test(org.junit.Test)

Example 4 with OutParameters

use of org.jdbi.v3.core.statement.OutParameters in project jdbi by jdbi.

the class TestOutParameterAnnotation method testMultipleOutParameters.

@Test
public void testMultipleOutParameters() {
    MyDao myDao = db.onDemand(MyDao.class);
    OutParameters outParameters = myDao.callMultipleOutParameters(1, 9);
    assertThat(outParameters.getInt("c")).isEqualTo(9);
    assertThat(outParameters.getInt("d")).isEqualTo(1);
}
Also used : OutParameters(org.jdbi.v3.core.statement.OutParameters) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 OutParameters (org.jdbi.v3.core.statement.OutParameters)3 Handle (org.jdbi.v3.core.Handle)1 Something (org.jdbi.v3.core.Something)1