好吧,如果您想从服务或实用程序类对 StoredProc 进行本地化调用,那么您可以将 Spring Jdbc 用于 StoredProc。实施见下文
public class StoredProcSampleTest extends StoredProcedure {
private static final String SPROC_NAME = "HH_EXTRACT.SAMPLE_TEST";
public StoredProcSampleTest(DataSource dataSource) {
super(dataSource, SPROC_NAME);
declareParameter(new SqlParameter("v_in_msg", Types.VARCHAR));
declareParameter(new SqlOutParameter("v_out_msg", Types.VARCHAR));
compile();
}
public String execute() {
HashMap<String, Object> hmap = new HashMap<String, Object>();
hmap.put("v_in_msg", "Suresh");
hmap.put("v_out_msg", "");
Map<String, Object> results = execute(hmap);
String outRes = (String) results.get("v_out_msg");
return outRes;
}
}
现在在您的实用程序类或服务类中,执行此操作
protected StoredProcSampleTest storedProcSampleTest;
@Autowired
public void setDataSource(final DataSource dataSource) {
this.storedProcSampleTest = new StoredProcSampleTest(dataSource);
}
:
public String callStoredProcSampleTest(){
return storedProcSampleTest.execute();
}