1

There are types:

CREATE OR REPLACE TYPE my_type IS OBJECT (
  id VARCHAR2(20),
  name VARCHAR2(40),
  phone NUMBER
);

I'm trying to create objects using these types:

....
Object[] myArray = new Object[3];
Object[] struct = new Object[values.size()];

int arrayIndex = 0;
for (User user : values) {
    myArray[0] = user.id().toString();
    myArray[1] = user.getName().toString();
    myArray[2] = user.getPhone();

    struct[arrayIndex++] = con.createStruct("my_type",myArray);
}

On the line with the creation of the structure of con.createStruct, an error occurs:

java.sql.SQLException: Inconsistent java and sql object types, for classes implementing ORAData or OracleData, respective factory classes ORADataFactory and OracleDataFactory should be registered in typeMap.

What can be wrong?

2 Answers 2

2
   myArray[0] = user.id().toString();
   myArray[1] = user.getName().toString();
   myArray[2] = user.getPhone();

This should be like:

-- First element of the array.
    myArray[0].id  = user.id().toString();
    myArray[0].name  = user.getName().toString();
    myArray[0].phone  = user.getPhone();
Sign up to request clarification or add additional context in comments.

Comments

0

You could employ class StructDescriptor from Oracle JDBC extensions:

StructDescriptor structDescriptor = StructDescriptor.createDescriptor("my_type",conn);
Object[] attributes = {user.id().toString(),
               user.getName().toString(),
               user.getPhone()};

new STRUCT(structDescriptor, connection, attributes);

https://docs.oracle.com/cd/E18283_01/appdev.112/e13995/oracle/sql/StructDescriptor.html

1 Comment

oracle.sql.ARRAY/ArrayDescriptor/STRUCT/StructDescriptor/.. depricated: docs.oracle.com/database/121/JAJDB/deprecated-list.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.