【问题标题】:Issues while Creating Oracle Array from List从列表创建 Oracle 阵列时的问题
【发布时间】:2017-04-11 05:29:06
【问题描述】:

我的代码流程看起来像:

1. Get a list of Attributes from a particular schema. This is ArrayList in type. 
2. The method given below receives the list and does the following  
   a. It converts it to an String/Object Array. 
   b. Connects to another Schema. 
   c. Iterate through a table and get the corresponding values from a field for those attributes. 
   d. Sends back to calling method so that the same can be updated for those attributes in primary schema. 

以下代码行出现错误:

Array itemDesc = ((OracleConnection)conn).createArrayOf("XXJN_PCM_ITEM_LIST", items);   

错误:java.sql.SQLFeatureNotSupportedException:不支持的功能 在 oracle.jdbc.driver.PhysicalConnection.createArrayOf(PhysicalConnection.java:15560)

我在项目中链接了 ojdbc6 jar,并且我也使用了 jar ojdbc7。但一直都是同样的错误。

下面是我的代码:

public HashMap MyMethod(ArrayList list) throws SQLException, Exception {
        HashMap itemsQtyMap = new HashMap();
        PreparedStatement psmt = null;
        Iterator iter = list.iterator();
        ResultSet resultSet = null;
        String itemNumber = null;
        double temp = 0;

        Object [] items = list.toArray();
        logger.info("Length of the converted array is " + items.length);
        OracleDataSource ds = new OracleDataSource();
        ds.setURL(PropertyNames.DB_URL);
        Connection conn = ds.getConnection(PropertyNames.DB_USERNAME,PropertyNames.DB_PASSWORD);
        logger.info("Connection is "+ conn);

/*This output in the logger is coming as Connection is oracle.jdbc.driver.T4CConnection@3de779fb */
        Array itemDesc = ((OracleConnection)conn).createArrayOf("XXJN_PCM_ITEM_LIST", items);   
        logger.info("Length of Item desc is "+ itemDesc);

        item = (String[]) list.toArray(item);
        Array itemDesc = ((OracleConnection) conn).createArrayOf("XXJN_PCM_ITEM_LIST", item);
*/
        oracle.sql.StructDescriptor x = StructDescriptor.createDescriptor("XXJN_PCM_ITEM_QRT_DEM", conn);
        ResultSetMetaData rsmd = x.getMetaData();
        int numberOfColumns = rsmd.getColumnCount();
        System.out.println("resultSet MetaData column Count=" + numberOfColumns);
        for (int i = 1; i <= numberOfColumns; i++) {
            logger.info("column MetaData ");
            logger.info("column number " + i);
            // get the column's name.
            logger.info(rsmd.getColumnName(i));
        }

        OracleCallableStatement cstmt = (OracleCallableStatement) conn.prepareCall("{ call xxjn_pcm_item_dem.item_qrt_dem(?,?)}");
        cstmt.setArray(1, itemDesc);
        cstmt.registerOutParameter(2, OracleTypes.ARRAY, "XXJN_PCM_ITEM_QRT_DEM_TBL");
        cstmt.execute();
        // Object[] dem = (Object[])cstmt.getObject(2);
        // Array dem = cstmt.getArray(2);
        Object[] dem = (Object[]) ((Array) cstmt.getObject(2)).getArray();

        System.out.println("length=" + dem.length);
        for (Object tmp : dem) {
            logger.info("Inside for Loop for Object TMP");
            OracleStruct row = (OracleStruct) tmp;


            Object[] attrs = row.getAttributes();

            // Attributes are index 1 based...
            // String sqlt = row.getSQLTypeName();
            //System.out.println("Item Number = " + (String) attrs[0]);
            DemandPopulationBean bean = new DemandPopulationBean();
            bean.setItemNumber((String) attrs[0]);
            bean.setQ1Demand(((BigDecimal) attrs[1]).doubleValue());
            bean.setQ1Demand(((BigDecimal) attrs[2]).doubleValue());
            bean.setQ1Demand(((BigDecimal) attrs[3]).doubleValue());
            bean.setQ1Demand(((BigDecimal) attrs[4]).doubleValue());

        }
        logger.info("---");

        //cstmt.close();
        return itemsQtyMap;
    }

问候, 麦

【问题讨论】:

  • 如果我理解正确,您是在尝试从 Java 创建一个数组吗?或者你想从数据库中获取数组列?
  • 你试过createOracleArray()的方法吗?
  • 是的,尝试过 createOracleArray() 但同样的例外。也尝试过 createARRAY()。我在这里尝试的是: 1. 转换 ArrayList >> 字符串数组 2. 数组 >> 从中创建 Oracle 数组。 3. 然后它将从代码中调用一个包,该包在旅途中创建一个临时表并获取相应的列。 Oracle Array 中提到的项目的值。
  • 看看this
  • 数据库中的XXJN_PCM_ITEM_LIST类型是如何定义的?

标签: java oracle jdbc


【解决方案1】:

问题现已解决。刚刚关闭 eclipse 并从头开始创建项目,这次它对我有用。我用了ojdb7 jar。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多