I have a stored procedure with a single integer output param and 5 varchar input params, no matter what I've tried I can't seem to get the output param back. I've ran the sproc on the db and it comes back with data, so I can't see what I'm doing wrong.
Does anyone know how to get an output param back from simplejdbccall?
I have something like this:
SimpleJdbcCall simpleJdbcCall =
new SimpleJdbcCall( getDatasourceForEnvironment() ).withProcedureName( "_Get_Id" ).declareParameters(
开发者_如何学JAVAnew SqlParameter( "MyID", Types.VARCHAR ), new SqlParameter( "MySourceID", Types.VARCHAR ),
new SqlParameter( "MyLocationID", Types.VARCHAR ), new SqlParameter( "MyVisitID", Types.VARCHAR ),
new SqlParameter( "MyVisitDate", Types.VARCHAR ) );
HashMap< String, String > input = new HashMap< String, String >();
input.put( "MyID", myObj.getMyID() );
input.put( "MySourceID", myObj.getMySourceID() );
input.put( "MyLocationID", myObj.getMyLocationID() );
input.put( "MyVisitID", myObj.getMyVisitID() );
input.put( "MyVisitDate", myObj.getMyVisitDate() );
System.out.println( simpleJdbcCall.execute( input ) );
There were 2 things I had wrong:
I was connected to the wrong database. Writing a more granular unit test revealed my error.
Since the return from "execute" is a map, the output params are case sensitive.
Long story short, there isn't anything special you need to do - Spring includes the output params by default. Furthermore, MapSqlParameterSource
is a much cleaner way to go with these sorts of methods.
精彩评论