JDBC調用Oracle存儲過程返回結果集並獲得輸出參數的實例是本文我們主要要介紹的內容,接下來我們就開始介紹這一過程,讓我們一起來了解一下吧。
- package xx.QQ.app;
- import Java.sql.CallableStatement;
- import Java.sql.Connection;
- import Java.sql.ResultSet;
- import org.springframework.beans.factory.BeanFactory;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.support.ClassPathXMLApplicationContext;
- import com.mchange.v2.c3p0.ComboPooledDataSource;
- /**
- * @author Jack Zhang Email:[email protected]
- * @date 2011-08-22
- */
- public class APPTest {
- public static void main(String[] args) throws Exception {
- ApplicationContext context = new ClassPathXMLApplicationContext(
- new String[] { "applicationContext.XML" });
- BeanFactory factory = (BeanFactory) context;
- ComboPooledDataSource dataSource = (ComboPooledDataSource) factory
- .getBean("dataSource");
- Connection con = dataSource.getConnection();
- CallableStatement st =con.prepareCall("{call package_user.PERSON_QUERY(?,?)}");
- //st.setString(1, "");
- st.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
- st.registerOutParameter(2, oracle.jdbc.OracleTypes.INTEGER);
- st.execute();
- ResultSet rs = null;
- rs = (ResultSet)st.getObject(1);
- while(rs.next())
- {
- System.out.println(rs.getObject(1)+" "+rs.getObject(2));
- }
- int count =st.getInt(2); //獲取輸出參數
- System.err.println(count);
- if (rs != null)
- rs.close();
- if (st != null)
- st.close();
- if (con != null)
- con.close();
- }
- }
- CREATE OR REPLACE PACKAGE package_user AS
- TYPE MY_RESULTSET_CURSOR IS REF CURSOR;
- PROCEDURE PERSON_QUERY(RS OUT MY_RESULTSET_CURSOR,C OUT INTEGER);
- END;
- create or replace package body package_user AS
- PROCEDURE PERSON_QUERY(RS OUT MY_RESULTSET_CURSOR,C OUT INTEGER)
- AS
- BEGIN
- OPEN RS FOR select * from emp;
- update A set ename='AAA';
- SELECT COUNT(*) INTO C from emp;
- END PERSON_QUERY;
- END;
以上就是JDBC調用Oracle存儲過程返回結果集並獲得輸出參數的全部過程,本文就介紹到這裡了,希望本次的介紹能夠對您有所收獲!