jdbc 调用存返回值的存储过程 及存储过程带 like 参数

create or replace procedure Proc_Educationhealth(regionCode in varchar2,invyear in varchar2 ,outsql out varchar2,cur_out_1 out sys_refcursor) is
v_sql varchar2(2000);
begin
v_sql := 'select count(COUNTY)  总县数, sum(TOTALPOPULATIONS)  年末总人口,sum(VILLAGEPOPULATIONS)  乡村人口 ,sum(TOTALVILLAGES)  行政村个数,
sum(NURSERYVILLAGES)  有幼儿园的行政村数,sum(HOSPITALVILLAGES)  有卫生室的行政村数,sum(LASTHOSPITALBEDS)  上年卫生机构床位数,
sum(LASTWELFAREBEDS)  社会福利机构床位数  from INV_COUNTY where COUNTY like ''%'|| regionCode || '%'' and  INVYEAR =' || invyear;
outsql :=v_sql;
open cur_out_1 for

v_sql;

end Proc_Educationhealth;
 
public class Test {
	
	public static void main(String[] args) throws Exception {
		Class.forName("oracle.jdbc.driver.OracleDriver");
		Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.1:1521:x","x","x");
		CallableStatement cstmt = conn.prepareCall("{call Proc_Educationhealth(?,?,?,?)}");
		cstmt.setString(1, "360721");
		cstmt.setString(2, "2012");
		cstmt.registerOutParameter(3,oracle.jdbc.OracleTypes.VARCHAR);
		cstmt.registerOutParameter(4,oracle.jdbc.OracleTypes.CURSOR);
		cstmt.execute();
		System.out.println(cstmt.getObject(3));
		 ResultSet rs = (ResultSet) cstmt.getObject(4);
		while(rs.next()){
			System.out.println(rs.getString("总县数")+"\t"+rs.getString("年末总人口"));
		}
	}
}
 

 

你可能感兴趣的:(jdbc)