Home > database >  Java call a stored procedure into the reference for the record type
Java call a stored procedure into the reference for the record type

Time:10-12

Java calls the oracle stored procedure into the RECORD type is, how to call? If let me change type please bypass, thank you

CodePudding user response:



refer to the original poster across your fingertips meteor response:
Java calls the oracle stored procedure into the RECORD type is, how to call? If let me change type please bypass, thank you

A similar list format [{' p_revealno ':' 12467 _x1}, {' p_revealno ':' 12480 _x1}], try?

CodePudding user response:

reference 1st floor weixin_39657173 response:
Quote: refer to the original poster across your fingertips meteor response:

Java calls the oracle stored procedure into the RECORD type is, how to call? If let me change type please bypass, thank you

A similar list format [{' p_revealno ':' 12467 _x1}, {' p_revealno ':' 12480 _x1}], try?

No, have to the OBJECT, RECORD is PLSQL, ORACLE did not OBJECT to convert

CodePudding user response:

Can be set outside a layer of the stored procedure, and then the parameter is the Java data types, within the stored procedure processing incoming parameters into record type,

CodePudding user response:

biubiu grey reference 3 floor response:
can set outside a layer of the stored procedure, and then the parameter is a Java data types, within the stored procedure processing incoming parameters into record type,

Finally changed the type of processing, the way you can

CodePudding user response:

Didn't change type to bypass, you ran to which go to

CodePudding user response:

/*
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# Perform the following SQL operations prior to running this sample
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Conn HR/HR;
The create or replace package TEST_PKG is
Type V_TYP is varrays (10) of varchar2 (200);
Type R_TYP is record (c1 pls_integer, c2 varchar2 (100));
Procedure VARR_PROC (in V_TYP p1, p2 OUT V_TYP);
Procedure REC_PROC (in R_TYP p1, p2 OUT R_TYP);
end;

The create or replace package body TEST_PKG is
Procedure VARR_PROC (in V_TYP p1, p2 OUT V_TYP) is
The begin
P2:=p;
end;
Procedure REC_PROC (in R_TYP p1, p2 OUT R_TYP) is
The begin
P2:=p;
end;
end;

*/

Import the Java. SQL. Array;
Import the Java. SQL. The CallableStatement.
Import the Java. SQL. Connection;
Import the Java. SQL. SQLException;
Import the Java. SQL. Struct;
Import the Java. SQL. Types;

The import oracle. JDBC. OracleConnection;
Public class PLSQLTypesSample
{
Public static void main (String [] args) throws SQLException
{
System. Out.println (" begin... ");
Connection conn=null;
. Oracle JDBC. Pool. OracleDataSource ods.=new oracle JDBC. Pool. OracleDataSource ();
Ods. SetURL (" JDBC: oracle: oci: localhost: 5521: wouldn ");
Ods. SetUser (" HR ");
Ods. SetPassword (" hr ");
//get the connection
Conn=ods. GetConnection ();

//call procedure TEST_PKG. VARR_PROC
The CallableStatement CSTMT=null;
Try {
CSTMT=conn. PrepareCall (" {call TEST_PKG. VARR_PROC (? ,?) } ");
//PLSQL varrays type binding
Array arr=((OracleConnection) conn.) createArray (" TEST_PKG. V_TYP ", new String [] {" A ", "B"});
CSTMT. SetArray (1, arr);
CSTMT. RegisterOutParameter (2 Types), ARRAY, "TEST_PKG. V_TYP");
CSTMT. The execute ();
//get PLSQL varrays type out the parameter value
Array outArr=CSTMT. GetArray (2);
//...
}
The catch (Exception e) {
e.printStackTrace();
} the finally {
If (CSTMT!=null)
CSTMT. Close ();
}

//call procedure TEST_PKG. REC_PROC
Try {
CSTMT=conn. PrepareCall (" {call TEST_PKG. REC_PROC (? ,?) } ");
//PLSQL RECORD type binding
Struct Struct=conn. CreateStruct (" TEST_PKG R_TYP ", the new Object [] {12345, "B"});
CSTMT. SetObject (1, struct);
CSTMT. RegisterOutParameter (2 Types), STRUCT, "TEST_PKG. R_TYP");
CSTMT. The execute ();
//get PLSQL RECORD type out the parameter value
Struct outStruct=(Struct) CSTMT. GetObject (2);
//...
}
The catch (Exception e) {
e.printStackTrace();
} the finally {
If (CSTMT!=null)
CSTMT. Close ();
}

if (conn !=null)
conn.close();

System. Out.println (" done!" );
}
}

Refer to the address: https://docs.oracle.com/database/121/JJDBC/apxref.htm#JJDBC28913
  • Related