vendredi 27 février 2015

Access Out parameter using NamedParameterJdbcTemplate

Am very new to spring. I want to call sql stored procedure using NamedParameterJdbcTemplate and access the value of the Out Parameter.Below is the code am writing. Should i add out parameter in mySqlParameters and how do i access the Out parameter after execution of the procedure.



CREATE PROCEDURE my_procedure(
in_id IN VARCHAR(25),
out_name OUT VARCHAR(25))

MapSqlParameterSource mySqlParameters = new MapSqlParameterSource();
mySqlParameters.addValue("in_id", myobj.getObj1());

final String myProc = "{call my_procedure(in_id,out_name)}";
NamedParameterJdbcTemplate Template = new NamedParameterJdbcTemplate(ds);

updateTemplate.execute(myProc , mySqlParameters ,
new PreparedStatementCallback<Boolean>() {

@Override
public Boolean doInPreparedStatement(PreparedStatement ps)
throws SQLException, DataAccessException {
return ps.execute();
//return ps.execute(myProc);
}

});

Aucun commentaire:

Enregistrer un commentaire