开发者

output param on simplejdbccall

开发者 https://www.devze.com 2023-04-01 06:16 出处:网络
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 com

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:

  1. I was connected to the wrong database. Writing a more granular unit test revealed my error.

  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消