2012年4月17日 星期二

callable StoreProcedure

ApplicationContext application = new ClassPathXmlApplicationContext("classpath:helloword/application.xml");
datasouce = (DataSource) application.getBean("ARDataSource");
DB_Conn = datasouce.getConnection();

// 設定 CallableStatement 
cs = DB_Conn.prepareCall("{call Tn_Pg_Wunhowchien.Tn_Pc_Test(?, ?, ?,?)}");
// 設定 IN參數的 Index 及值 
cs.setString(1, "test1");
// 定義 OUT 參數的 Index 與型態 
cs.registerOutParameter(2, OracleTypes.CURSOR);//import oracle.jdbc.OracleTypes;

cs.registerOutParameter(3, OracleTypes.VARCHAR);
cs.registerOutParameter(4, OracleTypes.VARCHAR);
// 執行並取回 OUT 參數值 
cs.execute(); 
System.out.println(cs.getString(3));    
System.out.println(cs.getString(4)); // OUT 回傳值 
ResultSet list= (ResultSet) cs.getObject(2);

if(list.next()){
 System.out.println(list.getString("Area_Cde"));
 System.out.println(list.getString("Phone_Nbr"));
}
 
資料來源:mkyong.com

沒有留言:

張貼留言