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