FoxyBOA
FoxyBOA

Reputation: 5846

SimpleJdbcCall: get result of Microsoft/Sybase stored procedure call

I've a Microsoft and Sybase stored procedures that return result as "return @value". I need to read the value from Java via SimpleJdbcCall.

Is it possible?

Upvotes: 2

Views: 4799

Answers (2)

LaGrandMere
LaGrandMere

Reputation: 10359

Use the SqlOutPutParameters :)

Here is an example :

SimpleJdbcCall countryProcedure = new SimpleJdbcCall(dataSource)
        .withoutProcedureColumnMetaDataAccess()
        .withProcedureName(procedureName)
        .declareParameters(new SqlOutParameter("RETURNCODE", Types.INTEGER))
        .declareParameters(new SqlOutParameter("RETURNMSG", Types.VARCHAR));
Map result = countryProcedure.execute();
        System.out.println("RETURNCODE: " + result.get("RETURNCODE"));
        System.out.println("RETURNMSG: " + result.get("RETURNMSG"));

Edit : I looked at it and there is a simpler way. Use the WithReturnValue() on your SimpleJdbcCall and the return value will be stored in the return Map under the "return" key.

Upvotes: 5

duffymo
duffymo

Reputation: 308763

Spring has supported stored procedures nicely since 2.x:

http://static.springsource.org/spring/docs/2.0.x/reference/jdbc.html

These should be able to sort you out.

Upvotes: 0

Related Questions