Wednesday, January 31, 2018

How to reuse ArrayDescriptor?

Leave a Comment

I tried the code below:

public class Abc {      private ArrayDescriptor arrayDesc;      void init() {        connection = //create connection         arrayDesc = ArrayDescriptor.createDescriptor("DBTYPE",connection);     }      void m1() {         conn1 = //create connection         ARRAY array_to_pass1 = new ARRAY( arrayDesc , conn1, idsArray1 );      }      void m2() {         conn2 = //create connection         ARRAY array_to_pass2 = new ARRAY( arrayDesc , conn2, idsArray2 );      }  } 

This code is giving the error below:

table.java.sql.SQLException: Missing descriptor at oracle.sql.DatumWithConnection.assertNotNull(DatumWithConnection.java:103)

How can this be resolved?

2 Answers

Answers 1

ArrayDescriptor is deprecated. Assuming your connection objects are of type OracleConnection, try using createOracleArray instead - something like this:

public class Abc {     void init() {         connection = //create connection     }      void m1() {         conn1 = //create connection         array array_to_pass1 = conn1.createOracleArray(arrayDesc, idsArray1);      }      void m2() {         conn2 = //create connection         array array_to_pass2 = conn2.createOracleArray(arrayDesc, idsArray2);      } } 

Note: Using this method, the arrays will be of type java.sql.Array rather than oracle.sql.ARRAY.

Answers 2

new ARRAY must be called with an ArrayDescriptor that uses the same connection. So what you're trying to do won't work. Note that each connection has a cache of descriptors so creating the descriptor will happen just once per connection.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment