stmt.execute ("CREATE TYPE o AS OBJECT(pno number(4),lname varchar2(10),fname varchar2(10),birth_date date,sex varchar2(1))");
stmt.execute ("CREATE TABLE PERSOBJECT(pobj o)");
// Create a new instance for person class Person p = new Person(); p.setPersonId(1); p.setLastName("melwyn"); p.setFirstName("barretto"); p.setBirthDate(java.sql.Date.valueOf("1976-06-12")); p.setGender("M"); // Insert into an object table pstmt=con.prepareStatement("insert into PERS_OBJECT values(?)");
My experience with Oracle objects is scant, but it looks like you are playing fast and loose with the names you are using. Your Java type returns "SCOTT.PERSON_TYPE" for its sql type, you create a database type called "o", create a table named "PERSOBJECT", then try to insert to a table named "PERS_OBJECT". I'm pretty sure all these names should be the identical. The example that I have seen also makes a Hashmap to relate the Java type's SQL name to the Java type's class: hmap.put("SOMEDBNAME.SOMETYPENAME", SomeClass.class); This map is used to tell the database know how to relate its database type to the Java class (called right after obtaining the Connection): connection.setTypeMap(hmap); There's some great documentation at the Oracle Technology Network. I'm sure they have a tutorial there.