JDBC调用Oracle存储过程返回结果集并获得输出参数的实例是本文我们主要要介绍的内容,接下来我们就开始介绍这一过程,让我们一起来了解一下吧。
class="dp-xml">
- 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:fish2-2@163.com
- * @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存储过程返回结果集并获得输出参数的全部过程,本文就介绍到这里了,希望本次的介绍能够对您有所收获!