使用自定义对象INPUT JDBC调用Oracle PL / SQL函数

时间:2018-06-29 08:17:20

标签: java oracle function

因此,我试图弄清楚如何将以下自定义对象(不包含在任何程序包中)传递给函数调用:

    CREATE OR REPLACE TYPE RABO_OWNER_DEV.SIANAGR_SEARCH_PARAM AS OBJECT
(
   pFilter        VARCHAR2(32000 CHAR),
   pOrderByCond   VARCHAR2(32000 CHAR),
   pScopeName     VARCHAR2(100 CHAR),
   ANACODANA      NUMBER(9),
   ANADENOM       VARCHAR2(180 CHAR),
   ANADENOMLANG2  VARCHAR2(180 CHAR),
   ANADENOMLANG3  VARCHAR2(180 CHAR),
   ANAFGIUR       VARCHAR2(10 CHAR),
   DSCOUNTRY      VARCHAR2(40 CHAR),
   ANACFISC       VARCHAR2(40 CHAR),
   ANAPIVA        VARCHAR2(40 CHAR),
   FROM_ANACODANA NUMBER(9),
   TO_ANACODANA   NUMBER(9),
   ANAEXCOD       VARCHAR2(30 CHAR),
   ANATIPPERS     VARCHAR2(1 CHAR),
   ANACODCAPOGRP  VARCHAR2(16 CHAR),
   ANACODDOC      VARCHAR2(10 CHAR),
   ANANUMDOC      VARCHAR2(15 CHAR),
   CLCINDTIPOIND  VARCHAR2(1 CHAR),
   CLCINDCODNAZ   VARCHAR2(10 CHAR),
   CLCINDPROV     VARCHAR2(10 CHAR),
   CLCINDLOC      VARCHAR2(100 CHAR),
   CLCINDCAP      VARCHAR2(10 CHAR),
   CLCINDIRIZZO   VARCHAR2(250 CHAR),
   CLCINDTEL      VARCHAR2(25 CHAR),
   CLCINDCELL     VARCHAR2(25 CHAR),
   CLCINDFAX      VARCHAR2(25 CHAR),
   CLCINDEMAIL    VARCHAR2(80 CHAR),
   CLCINDPEC      VARCHAR2(80 CHAR),
   CLCGRPNDG      VARCHAR2(16 CHAR),
   CLCGRPCODGRP   NUMBER(9),
   CLCGRPDESC     VARCHAR2(50 CHAR),
   MULTISEARCH    VARCHAR2(32000 CHAR),
   CLCTIPO        VARCHAR2(1 CHAR),
   ANACRISC       VARCHAR2(20 CHAR),
   ANASAE       VARCHAR2(10 CHAR),
   TELIMITCONS     NUMBER(1),
   TERICHOBLIO     NUMBER(1)
)
/

因此,首先,我认为可以从数据库中获取该对象,并且我已经在线搜索了一些内容,下面的代码是我发现的(我将在以后的属性中对其进行修改,但对于测试它是否有效,我照原样调用该方法):

void getAttributeInfo (Connection conn, String type_name) throws SQLException 
{ 
 // get the type descriptor 
 StructDescriptor desc = StructDescriptor.createDescriptor (type_name, conn); 

 // get type meta data 
 ResultSetMetaData md = desc.getMetaData (); 

 // get # of attrs of this type 
 int numAttrs = desc.getLength (); 

 // temporary buffers 
 String attr_name; 
 int attr_type; 
 String attr_typeName; 

 System.out.println ("Attributes of "+type_name+" :"); 
 for (int i=0; i<numAttrs; i++) 
 { 
   attr_name = md.getColumnName (i+1); 
   attr_type = md.getColumnType (i+1); 
   System.out.println (" index"+(i+1)+" name="+attr_name+" type="+attr_type); 

   // drill down nested object 
   if (attr_type == OracleTypes.STRUCT) 
   { 
     attr_typeName = md.getColumnTypeName (i+1); 

     // recursive calls to print out nested object meta data 
     getAttributeInfo (conn, attr_typeName); 
   } 
 } 
}

这是我的PL / SQL函数:

FUNCTION LS_SEARCH_SIANAGR(
   p_CodCompany   VARCHAR2,
   p_Bo_SessionID VARCHAR2 ,
   p_Context NUMBER,
   p_RowRead      OUT NOCOPY NUMBER,
   p_RowCount     OUT NOCOPY NUMBER,
   p_NumOfPages   OUT NOCOPY NUMBER,
   p_PAGE2EXTRACT NUMBER,
   p_WithActionInfo NUMBER,
   p_UseView NUMBER,
   p_searchParam  SIANAGR_SEARCH_PARAM
) RETURN SYS_REFCURSOR
AS
  PRAGMA AUTONOMOUS_TRANSACTION;
  v_Result SYS_REFCURSOR;
BEGIN

    LsSiSession.checkSession(p_CodCompany, p_Bo_SessionID, p_Context);  

  v_Result :=  LsAnaHeader_EL.LS_SEARCH_SIANAGR(
    p_CodCompany,
    p_Bo_SessionID,
    p_Context,
    p_RowRead,
    p_RowCount,
    p_NumOfPages,
    p_PAGE2EXTRACT,
    p_WithActionInfo,
    p_UseView,
    p_searchParam);
  COMMIT;
  RETURN v_Result;
EXCEPTION
  WHEN OTHERS THEN
    ROLLBACK;
    LsGlobal.LsErrorTrace(SQLERRM);
END;

然后,我将CallableStatement定义为:

CallableStatement cs = null;

getAttributeInfo (conn, "SIANAGR_SEARCH_PARAM");
String anagrSearchSql = "{call myPackage.myProcedure(?,?,?,...)}";

当我尝试运行时,我得到:

class java.lang.ClassCastException com.sun.proxy.$Proxy28 cannot be cast to oracle.jdbc.OracleConnection

在以下行:

StructDescriptor desc = StructDescriptor.createDescriptor (type_name, conn); 

我也搜索了此错误,但是我只发现我必须解开与“ OracleConnection”的连接,但是我没有找到目的。(Connection cannot be cast to oracle.jdbc.OracleConnection

这是我定义我的连接的方式:

public LinkRABOUnitService(String id, RTXManager mgr, Element descr) throws RTXException {
    super(id, mgr, descr);

    hbService = (HibernateService) mgr.getService(dbId + ".hibernate", HibernateService.class);
}

public Object execute(Map operationContext, Map sessionContext) throws RTXException {
    Session hbSession = null;
    boolean inTransaction = false;
    Connection connection = null;
    StringBuffer response = new StringBuffer();

    /* retrieve unit parameters */
    String xml = BeanHelper.asString(operationContext.get(getId() + ".xml"));
    String idCodeElaborazione = BeanHelper.asString(operationContext.get(getId() + ".idElaborazione"));

    try {
        // get hibernate session
        hbSession = locateTransactionSession(hbService, operationContext);
        if (hbSession != null) {
            inTransaction = true;
        } else {
            hbSession = openSession(hbService, operationContext, sessionContext);
        } ....

我是否需要搜索将自定义对象传递给oracle函数的另一种方法?

0 个答案:

没有答案