This discussion is archived
4 Replies Latest reply: Jun 20, 2013 1:03 AM by jwenting RSS

loading java issue

vxwo0owxv Newbie
Currently Being Moderated

I have the following code segment from asktom.com it can compile if I run it as a sql script but when I compile and pack the code as in Eclipse and load it into the db via sqldeveloper I get the following error

java.sql.SQLException: ORA-29509: incorrectly formed Java binary class definition

any help will really be appreciate.

 

 

CREATE OR REPLACE AND COMPILE

JAVA SOURCE NAMED "demo_passing_pkg"

AS

import java.io.*;

import java.sql.*;

import java.math.*;

import oracle.sql.*;

import oracle.jdbc.driver.*;

 

 

public class demo_passing_pkg extends Object{

 

 

public static void pass( java.lang.String p_in,

                         java.lang.String[] p_out ){

 

 

    /*

     * the simplest of datatypes -- the String.  If you remember

     * the C version with 6 formal parameters, null indicators,

     * strlen's, strcpy's and so on -- this is trivial in

     * comparision

     */

 

 

    if ( p_in != null ){

       

    System.out.println

        ( "The first parameter is " + p_in.toString() );

 

 

        p_out[0] = p_in.toUpperCase();

 

 

        System.out.println

        ( "Set out parameter to " + p_out[0].toString() );

    }

}

 

 

private static void show_array_info( oracle.sql.ARRAY p_in )

throws SQLException{

 

 

    System.out.println( "Array is of type      " +

                         p_in.getSQLTypeName() );

    System.out.println( "Array is of type code " +

                         p_in.getBaseType() );

    System.out.println( "Array is of length    " +

                         p_in.length() );

}

 

 

public static void

pass_str_array( oracle.sql.ARRAY p_in, oracle.sql.ARRAY[] p_out )

throws java.sql.SQLException,IOException{

 

 

    show_array_info( p_in );

    String[] values = (String[])p_in.getArray();

 

 

    for( int i = 0; i < p_in.length(); i++ )

        System.out.println( "p_in["+i+"] = " + values[i] );

 

 

    Connection conn = new OracleDriver().defaultConnection();

    ArrayDescriptor descriptor =

       ArrayDescriptor.createDescriptor( p_in.getSQLTypeName(), conn );

 

 

    p_out[0] = new ARRAY( descriptor, conn, values );

 

 

}

 

 

public static String return_string(){

    return "Hello World";

}

 

 

}

  • 1. Re: loading java issue
    jwenting Journeyer
    Currently Being Moderated

    Oracle supports only very specific class file formats, which correspond to specific compiler versions.

    Eclipse has its own compiler which is not 100% compatible with that in all the minor details.

  • 2. Re: loading java issue
    EJP Guru
    Currently Being Moderated

    Really? Eclipse doesn't obey the class file format? Details?

  • 3. Re: loading java issue
    rp0428 Guru
    Currently Being Moderated

    >

    I have the following code segment from asktom.com it can compile if I run it as a sql script but when I compile and pack the code as in Eclipse and load it into the db via sqldeveloper I get the following error

    >

    Then the solution is: DON'T DO THAT!

     

    Seriously - the simplest way to avoid problems with Java in the DB is to always load the source files. That allows Oracle to compile them using the DB version of Java (which for Oracle 11g is Java 1.5) and also ensure that the proper referenced classes are used.

     

    If your attempt to use class files created by Eclipse has problems it could be caused by the files being compiled by a different version of Java than that used by the DB.

    It isn't clear what you even mean by 'compile and pack the code' or if you are trying to load a class file or a jar file.

  • 4. Re: loading java issue
    jwenting Journeyer
    Currently Being Moderated

    Maybe it's fixed by now, but a few years ago we indeed ran into issues where Eclipse compiled class files were incompatible with a Sun JRE. Note this only happened with a few somewhat calls, 99%+ of things ran and run just fine.

    But there is a chance of it happening, whatever he did might have triggered it.