How can I call an oracle stored procedure with a returned value when connecting to an oracle database using java? The following describes how to use java to connect to a database to call an oracle stored procedure with returned values.
Oracle stored procedures with returned values are not listed)
The stored procedure is:
- CREATE OR REPLACE PROCEDURE TESTB(PARA1 IN VARCHAR2,PARA2 OUT VARCHAR2) AS
- BEGIN
- SELECT INTO PARA2 FROM TESTTB WHERE I_ID= PARA1;
- END TESTB;
Use the following code when calling in java:
- package com.hyq.src;
-
- public class TestProcedureTWO {
- public TestProcedureTWO() {
- }
- public static void main(String[] args ){
- String driver = "oracle.jdbc.driver.OracleDriver";
- String strUrl = "jdbc:oracle:thin:@127.0.0.1:1521:hyq";
- Statement stmt = null;
- ResultSet rs = null;
- Connection conn = null;
- try {
- Class.forName(driver);
- conn = DriverManager.getConnection(strUrl, " hyq ", " hyq ");
- CallableStatement proc = null;
- proc = conn.prepareCall("{ call HYQ.TESTB(?,?) }");
- proc.setString(1, "100");
- proc.registerOutParameter(2, Types.VARCHAR);
- proc.execute();
- String testPrint = proc.getString(2);
- System.out.println("=testPrint=is="+testPrint);
- }
- catch (SQLException ex2) {
- ex2.printStackTrace();
- }
- catch (Exception ex2) {
- ex2.printStackTrace();
- }
- finally{
- try {
- if(rs != null){
- rs.close();
- if(stmt!=null){
- stmt.close();
- }
- if(conn!=null){
- conn.close();
- }
- }
- }
- catch (SQLException ex1) {
- }
- }
- }
- }
-
- }
Note that the proc. the value 2 in getString (2) is not arbitrary, but corresponds to the out column in the stored procedure. If the out column is in the first position, it is proc. getString (1). If it is the third position, it is proc. getString (3), of course, you can also have multiple return values at the same time, that is, add a few more out parameters.
The preceding describes how to call oracle stored procedures with returned values when connecting to the database.
Oracle RMAN backup Optimization
Oracle backup using RMAN
Oracle EXP/IMP backup Overview
Importance of Oracle Database Backup
Oracle control file recovery