Skip to content
Muhammad Hewedy edited this page Mar 16, 2017 · 8 revisions

We have learned that, mostly all you need to do is to create a DAO interface and Mapper classes (classes the implement either ResultSetMapper or TypedOutputParamMapper), read more from the Mappers wiki page.

However, in one case you don't need to provide a Mapper at all. (other case is when your Stored procedure returns no result of course).

This case is when your stored procedure returns one and only one output parameter with no result set at all, in this case spwrap will do the mapping for you.

see this example

CREATE PROCEDURE my_create_cust_sp(firstname VARCHAR(50), lastname VARCHAR(50), 
                OUT custId INT, OUT code SMALLINT, OUT msg VARCHAR(50))
   	MODIFIES SQL DATA DYNAMIC RESULT SETS 1
   	BEGIN ATOMIC
    	INSERT INTO CUSTOMERS VALUES (DEFAULT, firstname, lastname);
    	SET custId = IDENTITY();
    	SET code = 0;
	END

NOTE The default behaviour is that every stored procedure need to have 2 output params as last 2 parameters in the stored procedure, and these two parameters doesn't appear to the user at all, and even this feature can turned off see configurations wiki page.

And the java DAO method looks like:

Integer createCustomer(@Param(VARCHAR) String firstName, @Param(VARCHAR) String lastName);

The above Stored procedure returns only one output parameter custId. In this case, instead of doing:

@Mapper(GenericIdMapper.class)
@StoredProc("my_create_cust_sp")
Integer createCustomer(@Param(VARCHAR) String firstName, @Param(VARCHAR) String lastName);

....

public class GenericIdMapper implements TypedOutputParamMapper<Integer>{
    // .....
}

You can just do:

@Scalar(Types.INTEGER)
@StoredProc("my_create_cust_sp")
Integer createCustomer(@Param(VARCHAR) String firstName, @Param(VARCHAR) String lastName);

That's all, no mapping class provided, only you need to specify the the SQL Type of the output parameter according to java.util.Types.