JAVA Implementation of calling the Oracle Stored Procedure

Source: Internet
Author: User

The most common operation between JAVA and Oracle is to call the Oracle stored procedure in JAVA. The following describes how to call the Oracle stored procedure in JAVA.

I. JAVA calls the Oracle stored procedure without output parameters]
The process name is pro1, the number of parameters is 1, and the data type is integer data.

 
 
  1. Import java. SQL .*;
  2.  
  3. Public class ProcedureNoArgs {
  4. Public static void main (String args []) throws Exception {
  5. // Load the Oracle driver
  6. DriverManager. registerDriver (new oracle. jdbc. driver. OracleDriver ());
  7. // Obtain the Oracle database connection
  8. Connection conn = DriverManager. getConnection (
  9. "Jdbc: oracle: thin :@ MyDbComputerNameOrIP: 1521: ORCL", sUsr, sPwd );
  10. // Create a stored procedure object
  11. CallableStatement c = conn. prepareCall ("{call pro1 (?)} ");
  12. // Set the parameter value of the Oracle stored procedure to 188.
  13. C. setInt (1,188 );
  14. // Execute the Oracle Stored Procedure
  15. C.exe cute ();
  16. Conn. close ();
  17. }
  18. }

Ii. How does JAVA call the Oracle stored procedure with output parameters]
The process name is pro2, the number of parameters is 2, the data type is integer data, the return value is Integer type

 
 
  1. Import java. SQL .*;
  2.  
  3. Public class ProcedureWithArgs {
  4. Public static void main (String args []) throws Exception {
  5. // Load the Oracle driver
  6. DriverManager. registerDriver (new oracle. jdbc. driver. OracleDriver ());
  7. // Obtain the Oracle database connection
  8. Connection conn = DriverManager. getConnection (
  9. "Jdbc: oracle: thin :@ MyDbComputerNameOrIP: 1521: ORCL", sUsr, sPwd );
  10. // Create an Oracle Stored Procedure object and call the Stored Procedure
  11. CallableStatement c = conn. prepareCall ("{call pro2 (?,?)} ");
  12. // Set the parameter value of the Oracle stored procedure to 188.
  13. C. setInt (1,188 );
  14. // Register the second parameter of the stored procedure
  15. C. registerOutParameter (2, java. SQL. Types. INTEGER );
  16. // Execute the Oracle Stored Procedure
  17. C.exe cute ();
  18. // Obtain and print the output parameter value of the stored procedure
  19. System. out. println (c. getInt (2 ));
  20. Conn. close ();
  21. }
  22. }

The above is the simplest example of calling the Oracle stored procedure in JAVA.

Instances that use oracle Stored Procedure Paging

How to delete ORACLE archive logs

Oracle mobile data file Method

Oracle Log File Reconstruction Method

Concepts of oracle users

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.