JDBC calls the Oracle stored procedure to return the result set and obtain the output parameter instance

Source: Internet
Author: User

JDBC calls the Oracle Stored ProcedureExamples of returning result sets and obtaining output parameters are the main content we will introduce in this article. Next we will introduce this process. Let's take a look at it.

 
 
  1. Package xx. qq. app;
  2. Import java. SQL. CallableStatement;
  3. Import java. SQL. Connection;
  4. Import java. SQL. ResultSet;
  5. Import org. springframework. beans. factory. BeanFactory;
  6. Import org. springframework. context. ApplicationContext;
  7. Import org. springframework. context. support. ClassPathXmlApplicationContext;
  8. Import com. mchange. v2.c3p0. ComboPooledDataSource;
  9. /**
  10. * @ Author Jack Zhang Email: fish2-2@163.com
  11. * @ Date 2011-08-22
  12. */
  13. Public class AppTest {
  14. Public static void main (String [] args) throws Exception {
  15. ApplicationContext context = new ClassPathXmlApplicationContext (
  16. New String [] {"applicationContext. xml "});
  17. BeanFactory factory = (BeanFactory) context;
  18. ComboPooledDataSource dataSource = (ComboPooledDataSource) factory
  19. . GetBean ("dataSource ");
  20. Connection con = dataSource. getConnection ();
  21. CallableStatement st = con. prepareCall ("{call package_user.PERSON_QUERY (?,?)} ");
  22. // St. setString (1 ,"");
  23. St. registerOutParameter (1, oracle. jdbc. OracleTypes. CURSOR );
  24. St. registerOutParameter (2, oracle. jdbc. OracleTypes. INTEGER );
  25. St.exe cute ();
  26. ResultSet rs = null;
  27. Rs = (ResultSet) st. getObject (1 );
  28. While (rs. next ())
  29. {
  30. System. out. println (rs. getObject (1) + "" + rs. getObject (2 ));
  31. }
  32. Int count = st. getInt (2); // get the output parameter
  33. System. err. println (count );
  34. If (rs! = Null)
  35. Rs. close ();
  36. If (st! = Null)
  37. St. close ();
  38. If (con! = Null)
  39. Con. close ();
  40. }
  41. }
 
 
  1. CREATE OR REPLACE PACKAGE package_user   AS    
  2. TYPE MY_RESULTSET_CURSOR IS REF CURSOR;    
  3. PROCEDURE PERSON_QUERY(RS OUT MY_RESULTSET_CURSOR,C OUT INTEGER);    
  4. END;    
  5. create or replace package body package_user AS    
  6. PROCEDURE  PERSON_QUERY(RS OUT MY_RESULTSET_CURSOR,C OUT INTEGER)    
  7. AS    
  8. BEGIN    
  9. OPEN RS FOR select * from emp;    
  10. update A set ename='AAA';    
  11. SELECT COUNT(*) INTO C from emp;    
  12. END PERSON_QUERY;    
  13. END;   

The above is the whole process of JDBC calling the Oracle stored procedure to return the result set and obtain the output parameters. This article will introduce it here. I hope this introduction will be helpful to you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.