I am using java.sql.SQLData interface to map my java objects to Oracle database types.
For example, I have an object type Person in Oracle DB defined as:
CREATE OR REPLACE TYPE PERSON AS OBJECT
(
PERSON_ID NUMBER,
PERSON_NAME VARCHAR2(100)
);
Corresponding Java type is:
public class Person implements SQLData {
private String sql_type = "PERSON";
private int personId;
private String personName;
public int getPersonId() {
return personId;
}
public void setPersonId(int personId) {
this.personId = personId;
}
public String getPersonName() {
return personName;
}
public void setPersonName(String personName) {
this.personName = personName;
}
public void readSQL(SQLInput stream, String typeName) throws SQLException
{
this.sql_type=typeName;
this.personId = stream.readLong();
this.personName = stream.readString();
}
public void writeSQL(SQLOutput stream) throws SQLException
{
stream.writeLong(this.personId);
stream.writeString(this.personName);
}
}
This works fine currently and populates Person Objects from database type.
Now, I have a another type and it’s corresponding collection as follows:
CREATE OR REPLACE TYPE SUBJECT AS OBJECT
(
SUBJECT_ID NUMBER,
SUBJECT_NAME VARCHAR2(100)
);
-- Corresponding List
CREATE OR REPLACE TYPE SUBJECT_LIST IS TABLE OF SUBJECT;
I have to create a new entry in type PERSON with this collection as follows:
CREATE OR REPLACE TYPE PERSON AS OBJECT
(
PERSON_ID NUMBER,
PERSON_NAME VARCHAR2(100),
SUBJECT_LIST TYPE SUBJECT_LIST
);
To make this change I have to change my java Person class. I tried adding java.sql.Array parameter but it is not working.
Can you please help here to map the new PERSON Object type to Java type?
Thanks in advance.
–Siddharth
The documentation of SQLInput (link below) has this on the first line…
“This interface [ie SQLInput] … is used by the driver behind the scenes, and a programmer never directly invokes SQLInput methods.”
Are you sure you should be using SQLInput directly? Is there an example you’re following?
Ref: http://java.sun.com/j2se/1.4.2/docs/api/java/sql/SQLInput.html#readObject%28%29