Problem in casting a database object to Java object

hi everyone,
Iam trying to execute following example which was provided in oracle documentation. iam planning to implement this concept in my project...But, i am not able to run...iam herewith enclosing the sample code and its error...Kindly help me out
import java.sql.*;
import java.io.*;
import java.util.*;
import java.math.BigDecimal;
import oracle.sql.*;
import oracle.jdbc.*;
public class PersonObject
public static void main (String args [])
throws Exception
// Register the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
// Connect to the database
// You need to put your database name after the @ sign in
// the connection URL.
// The sample retrieves an object of type "STUDENT",
// materializes the object as an object of type ADT.
// The Object is then modified and inserted back into the database.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@raman.monsanto.com:1521:ramdevl","multispec", "mspec");
// It's faster when auto commit is off
conn.setAutoCommit (false);
// Create a Statement
Statement stmt = conn.createStatement ();
try
stmt.execute ("drop table people");
stmt.execute ("drop type PERSON FORCE");
stmt.execute ("drop type ADDRESS FORCE");
catch (SQLException e)
System.out.println("Error during executing a statement: "+ e);
stmt.execute ("create type ADDRESS as object (street VARCHAR (30), num NUMBER)");
stmt.execute ("create type PERSON as object (name VARCHAR (30), home ADDRESS)");
stmt.execute ("create table people (empno NUMBER, empid PERSON)");
stmt.execute ("insert into people values(101, PERSON ('Greg', ADDRESS ('Van Ness', 345)))");
stmt.execute ("insert into people values(102, PERSON ('John', ADDRESS ('Geary', 229)))");
ResultSet rs = stmt.executeQuery ("select * from people");
System.out.println("This application works till extraction of data\n");
showResultSet (rs);
rs.close();
stmt.close();
conn.close();
public static void showResultSet (ResultSet rs)
throws SQLException
while (rs.next ())
ResultSetMetaData rsmd=rs.getMetaData();
System.out.println("the no of columns: "+rsmd.getColumnCount());
for(int i=0;i<rsmd.getColumnCount();i++)
System.out.println("The column no "+(i+1)+"is of type: "+rsmd.getColumnTypeName(i+1) );
int empno = rs.getInt (1);
// retrieve the STRUCT
(This line throws the error----->) STRUCT person_struct = (STRUCT)rs.getObject (2);
Object person_attrs[] = person_struct.getAttributes();
System.out.println ("person name: " + (String) person_attrs[0]);
STRUCT address = (STRUCT) person_attrs[1];
System.out.println ("person address: ");
Object address_attrs[] = address.getAttributes();
System.out.println ("street: " + (String) address_attrs[0]);
System.out.println ("number: " +
((BigDecimal) address_attrs[1]).intValue());
System.out.println ();
The error message is as follows:
sj -make -cdb newmodeltest.cdb -g -d D:\VisualCafe\Projects\ -classpath
D:\jdk1.3\jre\lib\classes12.zip;D:\VisualCafe\Projects\;D:\VISUALCAFE\JAVA\LIB\;D:\VISUALCAFE\JAVA\LIB\SYMCLASS.ZIP;D:\VISUALCAFE\JAVA\LIB\CLASSES.ZIP;D:\VISUALCAFE\JFC\SWINGALL.JAR;D:\VISUALCAFE\swing
-1.1\SWINGALL.JAR;D:\VISUALCAFE\JAVA\LIB\RT.JAR;D:\VISUALCAFE\BIN\COMPONENTS\SFC.JAR;D:\VISUALCAFE\BIN\COMPONENTS\SYMBEANS.JAR;D:\VISUALCAFE\JAVA\LIB\icebrowserbean.jar;D:\VISUALCAFE\JAVA\LIB\jsdk.jar;
D:\VISUALCAFE\JAVA\LIB\SYMTOOLS.JAR;D:\VISUALCAFE\BIN\COMPONENTS\TEMPLATES.JAR D:\VisualCafe\Projects\PersonObject.java
Build Successful
loading PersonObject.class for debugging...
PersonObject.class successfully loaded
This application works till extraction of data
the no of columns: 2
The column no 1is of type: NUMBER
The column no 2is of type: MULTISPEC.PERSON
java.lang.IncompatibleClassChangeError: class java.util.Hashtable does not implement interface java.util.Map
at oracle.sql.StructDescriptor.getClass(StructDescriptor.java:418)
at oracle.sql.STRUCT.toJdbc(STRUCT.java:365)
at oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:4195)
at oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:4123)
at oracle.jdbc.driver.OracleResultSetImpl.getObject(OracleResultSetImpl.java:401)
at PersonObject.showResultSet(PersonObject.java:106)
at PersonObject.main(PersonObject.java:54)
at symantec.tools.debug.MainThread.run(Agent.java:48)
Thanks in advance
Sudarshan.K

Since that implementation has existed since 1.2 and
the original post suggested that 1.3 was being used,I
don't see that a newer version would help any.That's not a good assumption. There could have been a
bug fix.
Could be. But for the particular error (IncompatibleClassChangeError) I would consider the chance almost non-existent until all other possibilities have been exhausted.

Similar Messages

  • Not able to convert SOAP object to java object

    Hi,
    I was able to get SOAP Response, but in that response string field is not able to be transformed into java object.
    Can you be able to give suggestion to solve this problem.
    Thanks in advance,

    Hi,
    You need to provide an example value that's failing and the date formats in the reference data you're using. It's more than likely you don't have the correct format in your ref data.
    regards,
    Nick

  • Mapping XML object to java object gives ClassCastException

    Hi All,
    I am trying to map a specific XML object to a specific java object using web
    services and received the following exception:
    java.lang.ClassCastException: weblogic.soap.xml.XMLObject
    at $Proxy0.getMonster(Unknown Source)
    at serviceClient.TestServiceClient.main(TestServiceClient.java:46)
    Exception in thread "main"
    I tried to map a simple type:
    <types>
    <schema targetNamespace='java:biomaterials'
    xmlns='http://www.w3.org/1999/XMLSchema'>
    <element name="Monster">
    <complexType>
    <all>
    <element name="name"
    type="string"/>
    <element name="age"
    type="int"/>
    </all>
    </complexType>
    </element>
    </schema>
    </types>
    To the following java bean:
    package biomaterials;
    public class
    ster{
    private String name;
    private Integer age;
    public Monster(String name, int age) {
    this.name=name;
    this.age=new Integer(age);
    public String getName() {
    return name;
    public void setName(String s) {
    this.name=s;
    public Integer getAge() {
    return age;
    public void setAge(int n) {
    this.age=new Integer(n);
    Here is my client code:
    package serviceClient;
    import java.util.Properties;
    import weblogic.soap.codec.CodecFactory;
    import weblogic.soap.codec.SoapEncodingCodec;
    import weblog
    ic.soap.codec.LiteralCodec;
    import weblogic.soap.WebServiceProxy;
    import weblogic.soap.SoapMethod;
    import weblogic.soap.SoapType;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.ejb.*;
    import biomaterials.ServiceSession;
    import java.io.File;
    import java.io.IOException;
    import org.w3c.dom.Element;
    import biomaterials.Monster;
    public class TestServiceClient
    public static void main( String[] arg ) throws Exception
    Properties h = new Properties();
    h.put(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.soap.http.SoapInitialContextFactory");
    h.put("weblogic.soap.wsdl.interface",
    ServiceSession.class.getName() );
    Context context = new InitialContext(h);
    ServiceSession serv =
    (ServiceSession)context.lookup("http://localhost:7001/biocat/biomaterials.Se
    rviceSession/biomaterials.ServiceSession.wsdl");
    //try
    //int result = serv.getTheNum();
    //String result=serv.getBIXBiologicals();
    //int result=serv.setBIXInfo("TARNUMBER");
    Monster result=serv.getMonster();
    System.out.print("The value is "+result);
    } /* end of main */
    } /* end of class */
    Here is the method in my stateless session bean:
    public Monster getMonster()
    return new Monster("Sully",3);
    And here is my whole wsdl file:
    <% response.setHeader( "Content-Type", "text/xml; charset=utf-8" ); %>
    <definitions
    targetNamespace="java:biomaterials"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/1999/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="java:biomaterials"
    >
    <types>
    <schema targetNamespace='java:biomaterials'
    xmlns='http://www.w3.org/1999/XMLSchema'>
    <element name="Monster">
    <complexType>
    <all>
    <element name="name" type="string"/>
    <element name="age" type="int"/>
    </all>
    </complexType>
    </element>
    </schema>
    </types>
    <message name="getBIXBiologicalsRequest"></message>
    <message name="getBIXBiologicalsResponse">
    <part name="return" type="xsd:string" />
    </message>
    <message name="setBIXInfoRequest">
    <part name="arg0" type="xsd:string" />
    <part name="arg1" type="xsd:string" />
    <part name="arg2" type="xsd:integer" />
    </message>
    <message name="setBIXInfoResponse"></message>
    <message name="getMonsterRequest"></message>
    <message name="getMonsterResponse">
    <part name="body" element="tns:Monster"/>
    </message>
    <portType name="ServiceSessionPortType">
    <operation name="getBIXBiologicals">
    <input message="tns:getBIXBiologicalsRequest"/>
    <output message="tns:getBIXBiologicalsResponse"/>
    I am using weblogic 6.1 SP1 on WIN NT.
    Please help me out in this issue.
    Thanks in advance.
    Sapan

    HI !
    i dont think that the servicepack is an issue in this case.
    anyway i ahve tried it on 6.1SP4 and still getting similar results.
    any pointers will be highly appreciated.
    Thanks,
    sapan
    "manoj cheenath" <[email protected]> wrote in message
    news:[email protected]...
    I just skimmed through your email. You said you
    are using WLS 6.1 SP1. Can you try this using
    the latest SP. There are many bug fixes done
    after SP1.
    Web service support in 6.1 is very limited. But, It
    looks like 6.1 can handle the case you are trying out.
    regards,
    -manoj
    "Sapan Agarwal" <[email protected]> wrote in message
    news:[email protected]...
    Hi All,
    I am trying to map a specific XML object to a specific java object usingweb
    services and received the following exception:
    java.lang.ClassCastException: weblogic.soap.xml.XMLObject
    at $Proxy0.getMonster(Unknown Source)
    at
    serviceClient.TestServiceClient.main(TestServiceClient.java:46)
    >>
    Exception in thread "main"
    I tried to map a simple type:
    <types>
    <schema targetNamespace='java:biomaterials'
    xmlns='http://www.w3.org/1999/XMLSchema'>
    <element name="Monster">
    <complexType>
    <all>
    <element name="name"
    type="string"/>
    <element name="age"
    type="int"/>
    </all>
    </complexType>
    </element>
    </schema>
    </types>
    To the following java bean:
    package biomaterials;
    public class
    ster{
    private String name;
    private Integer age;
    public Monster(String name, int age) {
    this.name=name;
    this.age=new Integer(age);
    public String getName() {
    return name;
    public void setName(String s) {
    this.name=s;
    public Integer getAge() {
    return age;
    public void setAge(int n) {
    this.age=new Integer(n);
    Here is my client code:
    package serviceClient;
    import java.util.Properties;
    import weblogic.soap.codec.CodecFactory;
    import weblogic.soap.codec.SoapEncodingCodec;
    import weblog
    ic.soap.codec.LiteralCodec;
    import weblogic.soap.WebServiceProxy;
    import weblogic.soap.SoapMethod;
    import weblogic.soap.SoapType;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.ejb.*;
    import biomaterials.ServiceSession;
    import java.io.File;
    import java.io.IOException;
    import org.w3c.dom.Element;
    import biomaterials.Monster;
    public class TestServiceClient
    public static void main( String[] arg ) throws Exception
    Properties h = new Properties();
    h.put(Context.INITIAL_CONTEXT_FACTORY,
    "weblogic.soap.http.SoapInitialContextFactory");
    h.put("weblogic.soap.wsdl.interface",
    ServiceSession.class.getName() );
    Context context = new InitialContext(h);
    ServiceSession serv =
    (ServiceSession)context.lookup("http://localhost:7001/biocat/biomaterials.Se
    rviceSession/biomaterials.ServiceSession.wsdl");
    file://try
    file://int result = serv.getTheNum();
    file://String result=serv.getBIXBiologicals();
    file://int result=serv.setBIXInfo("TARNUMBER");
    Monster result=serv.getMonster();
    System.out.print("The value is "+result);
    } /* end of main */
    } /* end of class */
    Here is the method in my stateless session bean:
    public Monster getMonster()
    return new Monster("Sully",3);
    And here is my whole wsdl file:
    <% response.setHeader( "Content-Type", "text/xml; charset=utf-8" ); %>
    <definitions
    targetNamespace="java:biomaterials"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/1999/XMLSchema"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="java:biomaterials"
    >
    <types>
    <schema targetNamespace='java:biomaterials'
    xmlns='http://www.w3.org/1999/XMLSchema'>
    <element name="Monster">
    <complexType>
    <all>
    <element name="name" type="string"/>
    <element name="age" type="int"/>
    </all>
    </complexType>
    </element>
    </schema>
    </types>
    <message name="getBIXBiologicalsRequest"></message>
    <message name="getBIXBiologicalsResponse">
    <part name="return" type="xsd:string" />
    </message>
    <message name="setBIXInfoRequest">
    <part name="arg0" type="xsd:string" />
    <part name="arg1" type="xsd:string" />
    <part name="arg2" type="xsd:integer" />
    </message>
    <message name="setBIXInfoResponse"></message>
    <message name="getMonsterRequest"></message>
    <message name="getMonsterResponse">
    <part name="body" element="tns:Monster"/>
    </message>
    <portType name="ServiceSessionPortType">
    <operation name="getBIXBiologicals">
    <input message="tns:getBIXBiologicalsRequest"/>
    <outputmessage="tns:getBIXBiologicalsResponse"/>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    I am using weblogic 6.1 SP1 on WIN NT.
    Please help me out in this issue.
    Thanks in advance.
    Sapan

  • Please help, probleme de connection to database oracle and  java

    Ihave a problem to make connection to database Oracle when I use a simple code of java
    ======================
    import java.sql.*;
    public class Exemple1 {
    public static void main (String args[]) {
    Statement stmt = null;
    Connection con=null;
    try {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    con = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:1521:GB","scott","tiger");
    catch (Exception e) { System.out.println(e);        }
    =================
    I have :
    * Linux (Fedora core3).
    * Oracle 10g
    My var. environ.:
    * ORACLE_HOME=/u01/app/oracle/product/10.1.0/Db_1
    * PATH=$ORACLE_HOME/bin
    * CLASSPATH=$ORACLE_HOME/jdbc/lib/ojdbc14.jar
    the error is:
    Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: oracle.sql.CharacterSet
    at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib/libgcj.so.5.0.0)
    at java.lang.Class.initializeClass() (/usr/lib/libgcj.so.5.0.0)
    at JvResolvePoolEntry(java.lang.Class, int) (/usr/lib/libgcj.so.5.0.0)
    at oracle.jdbc.driver.DBConversion.DBConversion(short, short, short) (Unknown Source)
    at oracle.jdbc.driver.T4CConnection.connect(java.lang.String, java.util.Properties) (Unknown Source)
    at oracle.jdbc.driver.T4CConnection.logon() (Unknown Source)
    I don't know what's heppen exactly?

    If
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    is replaced
    with
    Class.forName("oracle.jdbc.driver.OracleDriver");does the java.lang.NoClassDefFoundError: while resolving class: oracle.sql.CharacterSet get generated?

  • Problem with XMLEncoder for complex java object i

    Hi All.
    My problem with XMLEncoder is it doesnt transfrom java objects without default no arguement constructor. I was able to resolve this in my main java object class, by setting a new persistence delegate, but for other classes that are contained in the main class, they are not being encoded.
    Thanks in advance for your answers

    Better to put this in java forum :-)
    Just check, if this helps.
    http://forum.java.sun.com/thread.jspa?threadID=379614&messageID=1623434

  • How to insert a java object int derby database

    hi,
    i have a problem , ie..i want to insert my java object int database derby.and also i need to retrieve that object from database whenever i need. Any body help me to do that in derby...
    Thanks

    Or you would design a table where the columns of the table correspond to attributes of the object. Then you would make a row by writing out the attributes to the columns they correspond to.

  • Problem in connecting to database from webdynpro for java

    Hi
    I have a problem in connecting to database from webdynpro application
    I am using oracle 10 express edition as database and was able to connect to database from a java application.But  was unable to connect from a webdynpro for java.
    <b>I guess webdynpro for java uses open sql instead of vendor sql(I looked in the visual admin ,DB is using open sql) so unable to connect to database.Am i right.?</b>
    Do i need to make any settings in the visual admin to make it work?
    How to solve this problem.Please give me pointers
    Thanks
    Bala

    Hi,
    For connecting to Oracle, either you can use the normal JDBC connectivty code directly which is given below :
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@Oracle_server_ip:Oracle port:SID of the Database","user_name","password");
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("your query");
    In case you want to fetch data through ejbs, these are the steps to be followed :
    1) Open the J2EE perspective
    2) Create an EJB Module project
    3) Right click on ejbModule, create a new EJB (select your EJB type)
    4) While creating the ejb itself, you can add business methods by clicking ‘Next’ in the UI. Another option is after creating the ejb, write the method in the bean, then select the method from ejb-jar.xml -> <bean name> ->method. Right click and select ‘propogate to local & remote’.
    5) Double click on ejb-j2ee-engine.xml. select your bean and specify a Jndi name for eg: “MyJndi”.
    6) Right click on the EJB project and add ‘classes12.zip’ file (provided by Oracle) to it’s build path. (under libraries tab). Also check the same file under ‘Order & Export’.
    7) Create an Enterprise Application project.
    8) Right click on the EJB module project and select add to EAR project, then select the created EAR project.
    9) Right click on the EJB project, select ‘Build EJB Archive’
    10) Right click on the EAR project, select ‘Build Application Archive’
    11) Open the WebDynpro perspective, open a new project, right click on the project ->properties. Do the following configurations :-
    • Java Build path - select the EJB project from ‘projects’ , check the selected project under ‘Order & Export’
    • Project references – select the EAR project
    • WebDynpro references – select ‘sharing references’ tab, click add & make an entry as : <vendor>/<EAR project name without .ear extension>
    You can find the vendor name under ‘application-j2ee-engine.xml’ file of the EAR project. By default it is ‘sap.com’. So if my EAR project’s name is ABC, my entry would look like ‘sap.com/ABC’
    12) Now the configurations are over and the EJB can be invoked by writing the client code inside the webdynpro component. Like:
    InitialContext context = new InitialContext();
    Object obj = context.lookup("MyJndi");
    MyEJBHome home = MyEJBHome)PortableRemoteObject.narrow(obj,MyEJBHome.class);
    MyEJB mybean = home.create();
    int a = 0;
    a= mybean.add(10,15);
    wdContext.currentContextElement().setSum(a);
    where ‘MyEJB’ is my EJB name and ‘MyJndi’ is my JNDI name
    To connect to Oracle , you can write the usual Java code (given below) as a business methos of the ejb (similar to add() method in the example). And access it like mybean.<businessMethodName>().
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@Oracle_server_ip:Oracle port:SID of the Database","user_name","password");
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("your query");
    Extracted from Re: Webdynpro and Oracle
    http://help.sap.com/saphelp_webas630/helpdata/en/b0/6e62f30cbe9e44977c78dbdc7a6b27/frameset.htm
    May be of use to understand the VA Conf /people/varadharajan.krishnasamy/blog/2007/02/27/configuring-jdbc-connector-service-to-perform-database-lookups
    Regards
    Ayyapparaj

  • How to store java objects in the database

    Hi,
    I am trying to store HttpSession state across Application Servers. Basically I am trying to build a sort of application cluster server on my own. I thought the best way to do this was to periodically store the HttpSession object from an application server in a database.
    I created a table in Oracle 8i with a blob column. I use a PreparedStatement.setObject() method to store the HttpSession object in the database. My problem is, I don't know how to get the object back from the database.
    Since ResultSet.getBlob returns the Blob locator, I need to read the BinaryInputStream to get all my data back. This tells me that getBlob basically works only for things like files, and cannot be used for Java objects.
    Is there any way around this? Your input would be much appreciated.
    Regards,
    Somaiah.

    Thanks for the quick reply vramakanth.
    Do I have to use a type map if I do this? Also does such a type map exist for the HttpSession class?
    Thanks,
    Somaiah.

  • Get / Cast a Java Object

    Does anybody know how to get (or Cast) a Java Object returned from a Java method call ?
    Example:
    <cfset someList = object1.method1(someString, JavaCast("float",someNumber),...)>
    This method returns a list of Java object of type "Object2". ie. it returns List<Object2>
    Now I attempted to loop thru each objects from the returned list, and invoke some method on them, using code similar to below,
    <cfset var="#someList[index]#"/>
    but ColdFusion does not seem to understand the object "var" as Java "Object2". Is there any way I can cast the "var" to "Object2"?
    Thanks in advance.
    Xiaoling

    "var" is a reserved keyword! You can initialize variables with "var" in the beginning of a component, but do not use it as a variables name:
    <cfset var someVar = "#someList[index]#">

  • Ho to store java objects in oracle database

    HI
    for me the sceanario is,
    i neeed to create , dynamically a table at the time of specified action.
    i need to store the values retreieved from session and store it in a database..
    for example
    User usr=session.getAttribute("usr"); i need to store the user object.
    and hashtable and hashmap values without iterating.
    please suggest at the earliest
    can it be done?
    Regards,
    Ramesh

    my requirement is like that,bcos of two different weblogic servers need to acess the central database.which contains user information.
    The user object from first server will be stored in database.and the second server will retrieve the user information and it will set for its application.
    please suggest me how to store java objects in database.
    regards,
    Ramesh

  • Problem with using Postgres database in java.

    Hi ,
    I am using netbean netbean IDE 6.1.5 and postgres as my database.
    I want to pass a date to a query in java like-
    "select count(\"JOBID\") from emp
    to_char(\"STARTTIME\",'yyyy-MM-dd')=" + datestr
    where STARTTIME is a date field,
    but when I run the program it gives the error
    error: operator does not exist: text = integer
    even if I use this query
    ResultSet result1= stmt.executeQuery("select count(\"JOBID\") frrom emp "+
    " where to_date(\"STARTTIME\",'YYYY-MM-DD HH:MI:SS')=" + sqlDate);
    WHERE STARTDATE is string and
    sqlDate=java.sql.Date sqlDate
    it gives
    error:error: operator does not exist: date = integer
    please help
    moni

    Use PreparedStatement instead of Statement all the way. Not only it is faster and saves you from any SQL injection risks, but it also eases setting complex Java objects in a SQL query. It has for example a setDate() method.
    Prepare here: [http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html].

  • Passing Array of java objects to and from oracle database-Complete Example

    Hi all ,
    I am posting a working example of Passing Array of java objects to and from oracle database . I have struggled a lot to get it working and since finally its working , postinmg it here so that it coudl be helpful to the rest of the folks.
    First thinsg first
    i) Create a Java Value Object which you want to pass .
    create or replace and compile java source named Person as
    import java.sql.*;
    import java.io.*;
    public class Person implements SQLData
    private String sql_type = "PERSON_T";
    public int person_id;
    public String person_name;
    public Person () {}
    public String getSQLTypeName() throws SQLException { return sql_type; }
    public void readSQL(SQLInput stream, String typeName) throws SQLException
    sql_type = typeName;
    person_id = stream.readInt();
    person_name = stream.readString();
    public void writeSQL(SQLOutput stream) throws SQLException
    stream.writeInt (person_id);
    stream.writeString (person_name);
    ii) Once you created a Java class compile this class in sql plus. Just Copy paste and run it in SQL .
    you should see a message called "Java created."
    iii) Now create your object Types
    CREATE TYPE person_t AS OBJECT
    EXTERNAL NAME 'Person' LANGUAGE JAVA
    USING SQLData (
    person_id NUMBER(9) EXTERNAL NAME 'person_id',
    person_name VARCHAR2(30) EXTERNAL NAME 'person_name'
    iv) Now create a table of Objects
    CREATE TYPE person_tab IS TABLE OF person_t;
    v) Now create your procedure . Ensure that you create dummy table called "person_test" for loggiing values.
    create or replace
    procedure give_me_an_array( p_array in person_tab,p_arrayout out person_tab)
    as
    l_person_id Number;
    l_person_name Varchar2(200);
    l_person person_t;
    l_p_arrayout person_tab;
    errm Varchar2(2000);
    begin
         l_p_arrayout := person_tab();
    for i in 1 .. p_array.count
    loop
         l_p_arrayout.extend;
         insert into person_test values(p_array(i).person_id, 'in Record '||p_array(i).person_name);
         l_person_id := p_array(i).person_id;
         l_person_name := p_array(i).person_name;
         l_person := person_t(null,null);
         l_person.person_id := l_person_id + 5;
         l_person.person_name := 'Out Record ' ||l_person_name ;
         l_p_arrayout(i) := l_person;
    end loop;
    p_arrayout := l_p_arrayout;
         l_person_id := p_arrayout.count;
    for i in 1 .. p_arrayout.count
    loop
    insert into person_test values(l_person_id, p_arrayout(i).person_name);
    end loop;
    commit;
    EXCEPTION WHEN OTHERS THEN
         errm := SQLERRM;
         insert into person_test values(-1, errm);
         commit;
    end;
    vi) Now finally create your java class which will invoke the pl/sql procedure and get the updated value array and then display it on your screen>Alternatively you can also check the "person_test" tbale
    import java.util.Date;
    import java.io.*;
    import java.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.driver.*;
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    public class ArrayDemo
    public static void passArray() throws SQLException
    Connection conn = getConnection();
    ArrayDemo a = new ArrayDemo();
    Person pn1 = new Person();
    pn1.person_id = 1;
    pn1.person_name = "SunilKumar";
    Person pn2 = new Person();
    pn2.person_id = 2;
    pn2.person_name = "Superb";
    Person pn3 = new Person();
    pn3.person_id = 31;
    pn3.person_name = "Outstanding";
    Person[] P_arr = {pn1, pn2, pn3};
    Person[] P_arr_out = new Person[3];
    ArrayDescriptor descriptor =
    ArrayDescriptor.createDescriptor( "PERSON_TAB", conn );
    ARRAY array_to_pass =
    new ARRAY( descriptor, conn, P_arr);
    OracleCallableStatement ps =
    (OracleCallableStatement )conn.prepareCall
    ( "begin give_me_an_array(?,?); end;" );
    ps.setARRAY( 1, array_to_pass );
         ps.registerOutParameter( 2, OracleTypes.ARRAY,"PERSON_TAB" );
         ps.execute();
         oracle.sql.ARRAY returnArray = (oracle.sql.ARRAY)ps.getArray(2);
    Object[] personDetails = (Object[]) returnArray.getArray();
    Person person_record = new Person();
    for (int i = 0; i < personDetails.length; i++) {
              person_record = (Person)personDetails;
              System.out.println( "row " + i + " = '" + person_record.person_name +"'" );
                        public static void main (String args[]){
         try
                             ArrayDemo tfc = new ArrayDemo();
                             tfc.passArray();
         catch(Exception e) {
                        e.printStackTrace();
              public static Connection getConnection() {
         try
                             Class.forName ("oracle.jdbc.OracleDriver");
                             return DriverManager.getConnection("jdbc:oracle:thin:@<<HostNanem>>:1523:VIS",
                             "username", "password");
         catch(Exception SQLe) {
                        System.out.println("IN EXCEPTION BLOCK ");
                        return null;
    and thats it. you are done.
    Hope it atleast helps people to get started. Comments are appreciated. I can be reached at ([email protected]) or [email protected]
    Thanks
    Sunil.s

    Hi Sunil,
    I've a similar situation where I'm trying to insert Java objects in db using bulk insert. My issue is with performance for which I've created a new thread.
    http://forum.java.sun.com/thread.jspa?threadID=5270260&tstart=30
    I ran into your code and looked into it. You've used the Person object array and directly passing it to the oracle.sql.ARRAY constructor. Just curios if this works, cos my understanding is that you need to create a oracle.sql.STRUCT out of ur java object collection and pass it to the ARRAY constructor. I tried ur way but got this runtime exception.
    java.sql.SQLException: Fail to convert to internal representation: JavaBulkInsertNew$Option@10bbf9e
                        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
                        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
                        at oracle.jdbc.oracore.OracleTypeADT.toDatum(OracleTypeADT.java:239)
                        at oracle.jdbc.oracore.OracleTypeADT.toDatumArray(OracleTypeADT.java:274)
                        at oracle.jdbc.oracore.OracleTypeUPT.toDatumArray(OracleTypeUPT.java:115)
                        at oracle.sql.ArrayDescriptor.toOracleArray(ArrayDescriptor.java:1314)
                        at oracle.sql.ARRAY.<init>(ARRAY.java:152)
                        at JavaBulkInsertNew.main(JavaBulkInsertNew.java:76)
    Here's a code snippet I used :
    Object optionVal[] =   {optionArr[0]};   // optionArr[0] is an Option object which has three properties
    oracle.sql.ArrayDescriptor empArrayDescriptor = oracle.sql.ArrayDescriptor.createDescriptor("TT_EMP_TEST",conn);
    ARRAY empArray = new ARRAY(empArrayDescriptor,conn,optionVal);If you visit my thread, u'll see that I'm using STRUCT and then pass it to the ARRAY constructor, which works well, except for the performance issue.
    I'll appreciate if you can provide some information.
    Regards,
    Shamik

  • Is down casting possible in Java objects(reference variables)?

    I hope, Java up casting and down casting is possible in Java primitive variables like int float and so on.
    My doubt is,Does in object of Java(reference variables) support down casting?

    makpandian wrote:
    the ques i asked here is popped from my mind.We know that.
    But i did not get answer .Because you didn't do any research.
    Than s why i ask this here..That's the wrong approach. Do some research first. Use google, a textbook, a tutorial, the JLS, write some code, etc. etc.
    After spending time and effort doing that, if you still have questions, indicate clearly what you read and what part you didn't understand. The way you're doing it is NOT an effective way to learn, and it's a waste of everyone's time.

  • Tool to create Java Object classes using the Database Tables

    Hi,
    Is their any tools or utility available to create the Java Object Classes using the Database Tables as input.
    Lets Say I am having the Employee, Employee_Salary tables in the Database.The utility has to create the Java Object classes with the relation.
    Please Help...
    Thx..

    Hm, for generating regular Java classes I wouldn't know one from memory. But I suggest you start searching in for example the Eclipse marketspace for a third party plugin that can do it. If all fail, you could always use Hibernate Tools from the Jboss Tools Eclipse plugin set to generate Hibernate/JPA entities and then strip the annotations from them to turn them into regular POJO classes.
    How many tables are we talking about anyway? It might be less effort to just create the classes with properties and then use an IDE to generate getters and setters for them.

  • Store java Object in database

    Hi,
    firstly, excuse me for my english but i'm french.
    I need to store a java object. Is it possible to store a java object like a JPanel, an InetAdress, an URL, or an object of my conception in a database ?
    Anbd how should the table be declared ?

    Well first you need to learn how to use JDBC.
    With that knowledge available, you have two basic options:
    1) for each bean, write code to turn it into an insert statement / update statement / delete statement (easy, but lots of work)
    2) use the Java reflection API to automate the sql generation.
    A third option would be to use google and search for an API that can do this for you.

Maybe you are looking for

  • I lost my HD on my laptop, how do I get to the songs off my apple TV???

    About two weeks ago my HD crashed. I had it repaired and now when I try to access my apple TV it doesn't recognize my computer. All my music is on the HD of the apple TV. How do I get it back? Message was edited by: appstro

  • Installing Thinkvantage on a drive other than C

    Hi, I have installed Windows Vista 32b Business SP1 from DVD on drive C (partitioned at 20G) I want to install all Thinkvantage software on drive D under folder d:\programs instead of the default "C:\Program Files". Please advise how to change the de

  • How to restore the default web configuration in Lion

    Hi guys so I was messing around with apache/php/mysql, and after trying to enable openssl I think i made a mistake because when I try to enable web sharing by checking off the checkbox under system preferences it just turns back off right away. If i

  • Tricky Passing Event problem

    Hi, I have two files here. 1) MyFavorites 2) MyFavoritesItemRenderer I have a datagrid with an item renderer. The item renderer is essentially a delete image. I am trying to write a function so when the user clicks the image, it will remove the row f

  • Need Photoshop Elements RAW plugin for Canon 70D using MAC

    Need Photoshop Elements RAW plugin for Canon 70D using MAC - please advise where I can find it to download. Thanks.