0

My code flows looks likes :

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. 

I am getting error at following line of code :

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

Error: java.sql.SQLFeatureNotSupportedException: Unsupported feature at oracle.jdbc.driver.PhysicalConnection.createArrayOf(PhysicalConnection.java:15560)

I have ojdbc6 jar linked in project and i have used the jar ojdbc7 as well. But same error all time.

Below is my code :

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

Regards, MAK

mhasan
  • 3,703
  • 1
  • 18
  • 37
Mak
  • 1
  • 2
  • If I understand correctly, are you trying to create an array from Java? Or are you trying to get the array columns from the database? – Jacob Apr 11 '17 at 06:18
  • Have you tried `createOracleArray()` method? – Jacob Apr 11 '17 at 06:26
  • Yes, tried createOracleArray() but same exception on that.Tried createARRAY() as well. What i am trying here is : 1. Convert ArrayList >> String Array 2. Array >> Create Oracle Array from it. 3. It will then call a package from code which creates a temp table on the go and gets the corresponding column. values for item mentioned in Oracle Array. – Mak Apr 11 '17 at 07:56
  • Have a look at [this](http://stackoverflow.com/questions/32150369/java-calling-a-pl-sql-stored-procedure-with-arrays) – Jacob Apr 11 '17 at 08:04
  • How is the `XXJN_PCM_ITEM_LIST` type defined in the database? – MT0 Apr 11 '17 at 09:25
  • It's created as collection. Syntax used : create type xxjn_pcm_item_list as table of varchar2(100) – Mak Apr 12 '17 at 04:34

1 Answers1

0

The issue is resolved now. Just closed eclipse and created project from scratch, it worked this time for me. I used ojdb7 jar.

Mak
  • 1
  • 2