jdbc呼び出し格納戻り値の格納プロセスおよび格納プロセスlikeパラメータ

1644 ワード

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("     "));
		}
	}
}