jdbcTemplate 执行 存储过程
public class TestController {
private Logger logger=LoggerFactory.getLogger(this.getClass());
@Autowired
private JdbcTemplate jdbcTemplate;
public void execute2(){
int arg_id=60;
String start="2012-06-29 00.00.00";
String end="2012-07-20 23.59.59";
Object value = jdbcTemplate.execute(new CallableStatementCreatorFactory(arg_id,start,end),
new CallableStatementCallbackFactory());
System.out.println(value);
}
class CallableStatementCreatorFactory implements CallableStatementCreator {
private int arg_id;
private String start;
private String end;
public CallableStatementCreatorFactory(int argId, String start,
String end) {
super();
arg_id = argId;
this.start = start;
this.end = end;
}
public CallableStatement createCallableStatement(Connection arg0)
throws SQLException {
CallableStatement demo3 = arg0.prepareCall("call demo3(?,?,?,?)");
demo3.setInt("arg_id",arg_id);
demo3.setString("start", start);
demo3.setString("end", end);
demo3.registerOutParameter("bilv", Types.DOUBLE);
return demo3;
}
}
class CallableStatementCallbackFactory implements CallableStatementCallback<Double>{
public Double doInCallableStatement(CallableStatement arg0)
throws SQLException, DataAccessException {
ResultSet rs=null;
try{
arg0.execute();
double obj = arg0.getDouble("bilv");
return obj;
}catch (Exception e) {
e.printStackTrace();
return 1.0;
}
}
}
}