JDBC程序,用于调用具有复杂输入和输出的存储过程

时间:2012-01-12 15:23:04

标签: java jdbc

你能帮我写一下JDBC程序来调用下面那个具有复杂输入类型的存储过程。

以下是我的存储过程定义

CREATE OR REPLACE TYPE inputObjects_t AS OBJECT (
    serviceID        VARCHAR2(7),
    offerID          VARCHAR2(7),
    transactionID    NUMBER
)

CREATE OR REPLACE TYPE inputArray_t IS VARRAY(100) OF inputObjects_t

PROCEDURE CheckObjectInput( pCustomerRef IN VARCHAR2,
                                 pSubscriptionPS IN NUMBER,
                                 pExpiryObjects IN inputArray_t,
                                 pTransactionDtm IN DATE,
                                 pTransactionID IN NUMBER);

PROCEDURE CheckObjectOutput( pCustomerRef IN VARCHAR2,
                                 pSubscriptionPS IN NUMBER,
                                 pExpiryObjects OUT inputArray_t,
                                 pTransactionDtm IN DATE,
                                 pTransactionID IN NUMBER);

2 个答案:

答案 0 :(得分:1)

如果您使用Oracle,请使用课程OracleCallableStatement 有一种名为setSTRUCT的方法。

一般例子:

OracleConnection conn = (...)
OracleCallableStatement cs = (OracleCallableStatement) conn.prepareCall(sql);
StructDescriptor sd = StructDescriptor.createDescriptor("MY_TYPENAME", conn);
Object[] attribs = new Datum[3];
attribs[0] = new CHAR("value1",  charSet);
attribs[1] = new CHAR("value2",  charSet);
CLOB clob2 = attribs[2] = new CLOB(conn);
STRUCT st = new STRUCT(sd, conn, attribs);
(...)
cs.setSTRUCT(n, st);
(...)
cs.execute()

答案 1 :(得分:0)

您将希望池存储数据库连接,然后调用存储过程的方法。你可能想要这样的东西:

public callStoredProc(String serviceID, String offerID, Integer trasnactionID) {
   try {
   myConnection.startTransaction();
   StringBuilder mySQL = new StringBuilder();
   ... build sql statement ...
   myConnection.execute(mySQL.toString());
   } catch (SQLException sqle) {
   ...
   } finally {
      myConnection.endTransaction();
      ... sql cleanup ...
   }
}