丶叫我皇帝陛下

博客园 首页 新随笔 联系 订阅 管理

第一步先来了解一个类 StoredProcedure 是一个抽象类 ,你需要自己扩展其实现

下面我们以实例来讲解。


import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.jdbc.datasource.DriverManagerDataSource;

public class MyJDBC {

private static DataSource dataSource = null;

public static Object executeProcedure(final String proc,
LinkedHashMap inParams, LinkedHashMap outParams) {
Map map = inParams;//参数列表
HashMap struct = new HashMap();
struct.put("dataSource", getDataSource());//数据源
struct.put("sql", proc);//执行存储过程名称
struct.put("in", inParams);//输入参数
struct.put("out", outParams);//输出参数
MyStoredProcedure st = new MyStoredProcedure(struct);//构造扩展的StoredProcedure
 return st.execute(map);//执行
}

public static DataSource getDataSource() {
if (dataSource == null)
dataSource = new DriverManagerDataSource(
"oracle.jdbc.OracleDriver",
"url", "username",
"password");
return dataSource;
}

public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}

}

第二步 编写扩展的StoredProcedure


好了 可以测试了 是不是很简单啊


posted on 2013-05-13 10:04  丶叫我皇帝陛下  阅读(222)  评论(0)    收藏  举报