Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

output param on simplejdbccall

Tags:

java

spring

jdbc

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(
            new 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 ) );
like image 581
javamonkey79 Avatar asked Jan 21 '26 18:01

javamonkey79


1 Answers

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.

like image 161
javamonkey79 Avatar answered Jan 24 '26 08:01

javamonkey79