@Test public void testOutParameter() { MyDao myDao = db.onDemand(MyDao.class); OutParameters outParameters = myDao.callStoredProc(); assertThat(outParameters.getInt("outparam")).isEqualTo(100); }
@Test public void testStatement() { OutParameters ret = h.createCall("? = CALL TO_DEGREES(?)") .registerOutParameter(0, Types.DOUBLE) .bind(1, 100.0d) .invoke(); Double expected = Math.toDegrees(100.0d); assertThat(ret.getDouble(0)).isEqualTo(expected, Offset.offset(0.001)); assertThat(ret.getLong(0).longValue()).isEqualTo(expected.longValue()); assertThat(ret.getShort(0).shortValue()).isEqualTo(expected.shortValue()); assertThat(ret.getInt(0).intValue()).isEqualTo(expected.intValue()); assertThat(ret.getFloat(0).floatValue()).isEqualTo(expected.floatValue(), Offset.offset(0.001f)); assertThatExceptionOfType(Exception.class).isThrownBy(() -> ret.getDate(1)); assertThatExceptionOfType(Exception.class).isThrownBy(() -> ret.getDate(2)); }
@Test public void testStatementWithNamedParam() { OutParameters ret = h.createCall(":x = CALL TO_DEGREES(:y)") .registerOutParameter("x", Types.DOUBLE) .bind("y", 100.0d) .invoke(); Double expected = Math.toDegrees(100.0d); assertThat(ret.getDouble("x")).isEqualTo(expected, Offset.offset(0.001)); assertThat(ret.getLong("x").longValue()).isEqualTo(expected.longValue()); assertThat(ret.getShort("x").shortValue()).isEqualTo(expected.shortValue()); assertThat(ret.getInt("x").intValue()).isEqualTo(expected.intValue()); assertThat(ret.getFloat("x")).isEqualTo(expected.floatValue()); assertThatExceptionOfType(Exception.class).isThrownBy(() -> ret.getDate("x")); assertThatExceptionOfType(Exception.class).isThrownBy(() -> ret.getDate("y")); }
@Test public void testCall() { Handle handle = db.getHandle(); handle.execute(findSqlOnClasspath("create_stored_proc_add")); // tag::invokeProcedure[] OutParameters result = handle .createCall("{:sum = call add(:a, :b)}") // <1> .bind("a", 13) // <2> .bind("b", 9) // <2> .registerOutParameter("sum", Types.INTEGER) // <3> <4> .invoke(); // <5> // end::invokeProcedure[] // tag::getOutParameters[] int sum = result.getInt("sum"); // end::getOutParameters[] assertThat(sum).isEqualTo(22); } }
@Test public void testOutParameter() { MyDao myDao = db.onDemand(MyDao.class); OutParameters outParameters = myDao.callStoredProc(); assertThat(outParameters.getInt("outparam")).isEqualTo(100); }