从List创建Oracle数组时出现的问题

时间:2017-04-11 05:29:07

标签: java oracle jdbc

我的代码流看起来像:

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;
    }

此致 MAK

1 个答案:

答案 0 :(得分:0)

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