Spring 2.5中调用Oracle存储过程

 /**调用存储过程
  存储过程
   create or replace procedure getselect(arg in varchar2,out_result out sys_refcursor)
   is
   begin
    open out_result for select * from user_tab_cols a where a.table_name = arg;
   end  getselect;
   */

 public void getCallableStatementCallback(){
  ApplicationContext context = new FileSystemXmlApplicationContext(
  "src/database_config.xml");
  JdbcTemplate jt = new JdbcTemplate((DataSource) context.getBean("oracleDataSourceTest"));
  // 测试用的方法
  List relist = (List) jt.execute("call getselect(?,?)",
    new CallableStatementCallback() {
     public Object doInCallableStatement(CallableStatement cs)
       throws SQLException, DataAccessException {
      cs.setString(1, "ACCT");
      cs.registerOutParameter(2,oracle.jdbc.driver.OracleTypes.CURSOR);
      cs.execute();
      ResultSet rs = (ResultSet) cs.getObject(2);
      List result = new ArrayList();
      while (rs != null && rs.next()) {
       Map map = new HashMap();
       map.put("TABLE_NAME", rs.getString(1));
       map.put("COLUMN_NAME", rs.getString(2));
       result.add(map);
      }
      rs.close();
      return result; // 返回类型决定execute返回类型
     }
    });
  for (int i = 0; i < relist.size(); i++) {
   Map rmap = (Map) relist.get(i);
   System.out.println(rmap.get("TABLE_NAME") + " "+ rmap.get("COLUMN_NAME"));
  }
 }

你可能感兴趣的:(spring,oracle,xml,jdbc)