存储过程调用
Connectin conn = DBUtil.getConnection();
DatabaseMetaData dbmd = conn.getMetaData();
//获取数据库数据元
//获取存储过程的参数列表
ResultSet rs =
dbmd.getProcedureColumns(packageName, "", procedure, null);
while(rs.next()){
String columnName=rs.getString("
COLUMN_NAME");//获取参数名称
int columnType = rs.getInt("
COLUMN_TYPE");//获取参数类型
in dateType = rs.getInt("
DATA_TYPE");//获取参数数据类型
}
String sql = "{call procedureName(p1=>?,p2=>?,p3=>?,p4=>?)}";
CallableStatement
call=conn.
prepareCall(sql);//获取存储过程对象
call.setObject(1,obj1);//传入参数
call.setObject(2,obj1);
call.registerOutParameter(2,obj2_sql_type);//声明返回数据类型
call.registerOutParameter(3,obj3_sql_type);
call.registerOutParameter(4,obj4_sql_type);
call.execute();//调用存储过程
Object val2=
call.getObject(2);//获取返回参数值
Object val3=call.getObject(3);
Object val4=call.getObject(4);
call.commit();//提交
call.close();//关闭
rs.close();
conn.close();