您的位置:首页 > 编程语言 > Java开发

java调用存储过程

2016-01-17 15:11 447 查看
try {
DBConnection dbs = new DBConnection();
conn = dbs.getConnection();
stmt = conn.prepareCall("{call PAK_ExecuteAttendingDoctor.ExecuteAttendingDoctor (?,?,?)}");//前两个为参数,第三个为输出
         //存储过程内容详见http://www.cnblogs.com/wuhailong/p/5137254.html
stmt.registerOutParameter(1, OracleTypes.VARCHAR);//参数
stmt.registerOutParameter(2, OracleTypes.VARCHAR);//存数
stmt.registerOutParameter(3, OracleTypes.CURSOR);//游标
stmt.setString(1, start_time);
stmt.setString(2, end_time);
if (true) {
String ss = "select dept_name from lcp_local_dept where dept_code='"
+ deptcodevalue + "'";
DatabaseClass db1 = LcpUtil.getDatabaseClass();
String deptName = "";
deptName = db1.FunGetDataSetBySQL(ss).FunGetDataAsStringById(0,
0);
// stmt.setString(3,deptName);
stmt.execute();
rs = (ResultSet) stmt.getObject(3);
while (rs.next()) {
String execute_dept = rs.getString("execute_dept");
String attending_doctor = rs.getString("attending_doctor");
int fhrs = rs.getInt("fhrs");
int nrrs = rs.getInt("nrrs");
int wcrs = rs.getInt("wcrs");
double nrl = rs.getDouble("nrl");
double wcl = rs.getDouble("wcl");
int xdyzzs = rs.getInt("xdyzzs");
int xdlcljyzs = rs.getInt("xdlcljyzs");
double xdl = rs.getDouble("xdl");
data.add(new Object[] { execute_dept, attending_doctor,
fhrs, nrrs, wcrs, nrl, wcl, xdyzzs, xdlcljyzs, xdl });
}
}
} catch (Exception e) {
System.out.println("存储过程取数据出错!!" + e.getMessage());
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
stmt = null;
}
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
rs = null;
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
statement = null;
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
conn = null;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: