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.
- Import java. SQL .*;
-
- Public class ProcedureNoArgs {
- Public static void main (String args []) throws Exception {
- // Load the Oracle driver
- DriverManager. registerDriver (new oracle. jdbc. driver. OracleDriver ());
- // Obtain the Oracle database connection
- Connection conn = DriverManager. getConnection (
- "Jdbc: oracle: thin :@ MyDbComputerNameOrIP: 1521: ORCL", sUsr, sPwd );
- // Create a stored procedure object
- CallableStatement c = conn. prepareCall ("{call pro1 (?)} ");
- // Set the parameter value of the Oracle stored procedure to 188.
- C. setInt (1,188 );
- // Execute the Oracle Stored Procedure
- C.exe cute ();
- Conn. close ();
- }
- }
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
- Import java. SQL .*;
-
- Public class ProcedureWithArgs {
- Public static void main (String args []) throws Exception {
- // Load the Oracle driver
- DriverManager. registerDriver (new oracle. jdbc. driver. OracleDriver ());
- // Obtain the Oracle database connection
- Connection conn = DriverManager. getConnection (
- "Jdbc: oracle: thin :@ MyDbComputerNameOrIP: 1521: ORCL", sUsr, sPwd );
- // Create an Oracle Stored Procedure object and call the Stored Procedure
- CallableStatement c = conn. prepareCall ("{call pro2 (?,?)} ");
- // Set the parameter value of the Oracle stored procedure to 188.
- C. setInt (1,188 );
- // Register the second parameter of the stored procedure
- C. registerOutParameter (2, java. SQL. Types. INTEGER );
- // Execute the Oracle Stored Procedure
- C.exe cute ();
- // Obtain and print the output parameter value of the stored procedure
- System. out. println (c. getInt (2 ));
- Conn. close ();
- }
- }
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