Search in sources :

Example 6 with SqlOutParameter

use of org.springframework.jdbc.core.SqlOutParameter in project spring-framework by spring-projects.

the class SimpleJdbcCallTests method testAddInvoiceFuncWithoutMetaDataUsingMapParamSource.

@Test
public void testAddInvoiceFuncWithoutMetaDataUsingMapParamSource() throws Exception {
    initializeAddInvoiceWithoutMetaData(true);
    SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withFunctionName("add_invoice");
    adder.declareParameters(new SqlOutParameter("return", Types.INTEGER), new SqlParameter("amount", Types.INTEGER), new SqlParameter("custid", Types.INTEGER));
    Number newId = adder.executeFunction(Number.class, new MapSqlParameterSource().addValue("amount", 1103).addValue("custid", 3));
    assertEquals(4, newId.intValue());
    verifyAddInvoiceWithoutMetaData(true);
    verify(connection, atLeastOnce()).close();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) SqlOutParameter(org.springframework.jdbc.core.SqlOutParameter) Test(org.junit.Test)

Example 7 with SqlOutParameter

use of org.springframework.jdbc.core.SqlOutParameter in project spring-framework by spring-projects.

the class SimpleJdbcCallTests method testAddInvoiceProcWithoutMetaDataUsingArrayParams.

@Test
public void testAddInvoiceProcWithoutMetaDataUsingArrayParams() throws Exception {
    initializeAddInvoiceWithoutMetaData(false);
    SimpleJdbcCall adder = new SimpleJdbcCall(dataSource).withProcedureName("add_invoice");
    adder.declareParameters(new SqlParameter("amount", Types.INTEGER), new SqlParameter("custid", Types.INTEGER), new SqlOutParameter("newid", Types.INTEGER));
    Number newId = adder.executeObject(Number.class, 1103, 3);
    assertEquals(4, newId.intValue());
    verifyAddInvoiceWithoutMetaData(false);
    verify(connection, atLeastOnce()).close();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) SqlOutParameter(org.springframework.jdbc.core.SqlOutParameter) Test(org.junit.Test)

Aggregations

SqlOutParameter (org.springframework.jdbc.core.SqlOutParameter)7 Test (org.junit.Test)6 SqlParameter (org.springframework.jdbc.core.SqlParameter)6 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)3 ArrayList (java.util.ArrayList)2 SqlInOutParameter (org.springframework.jdbc.core.SqlInOutParameter)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 InvalidDataAccessApiUsageException (org.springframework.dao.InvalidDataAccessApiUsageException)1 DriverManagerDataSource (org.springframework.jdbc.datasource.DriverManagerDataSource)1