Problems using Java classes in Oracle Database

Asked

Viewed 419 times

5

I’m having trouble using classes Java a little "complex" in the Oracle. When I use a simple class, as an example below:

 CREATE JAVA SOURCE NAMED "Welcome" AS
   public class Welcome {
      public static String welcome() {
         return "Welcome World";   
      } 
   }

It works perfectly, but when it’s a class I need to instantiate an object from a lib, I have problems and can’t use the class, and with the PL/SQL Developer, my class compiles only with error, and with great difficulty identified that the error at the time I instate the class. The code follows below:

CREATE JAVA SOURCE NAMED "Importar" AS
public class Importar
    import org.pentaho.di.trans.Trans;
    import org.pentaho.di.trans.TransMeta;

    public static String void executar(String arquivo) throws IOException
    {
         Trans trans; // AQUI TENHO O ERRO...
         TransMeta transMeta = new TransMeta(this.loaderName); 
         trans = new Trans(transMeta); 
         ...
         return "resultado...";
    }

The problem is that in the PL/SQL Developer tool, I could only identify the error because I was commenting on the code line by line and only when I commented on the Trans object, the code compiled without errors.

I already performed the test running the class in Eclipse and it compiles without error and runs without any problem, however as the error occurs in PL/SQL Developer, I believe it must be some specific error of some Oracle rule.

I wonder if it is possible, in Oracle, to perform this type of object instantiation?

  • 1

    Erico, take a look at the documentation Linkei gave in the answer to this question: http://answall.com/questions/28867/chamar-classe-java-dentro-do-oracle/28879#28879 . You can compile the class outside of Oracle and load it + Classpath dependencies, or even a jar inside Oracle.

  • Thank you @Anthonyaccioly, because it is, I believe that in my case I will even have to compile the class outside of Oracle, and maybe generate a jar and load into Oracle. Outside of Oracle the code compiles and works correctly, but in Oracle it complains "Compiled with errors" and only managed to get this message when I deleted the line where I instate the Trans class.

  • Erico, this happens because the classes of Pentaho are not in Classpath when compiling. You can generate a jar Uber with all classes or configure the Classpath manually during the loading, but also investigate other options like exposing Web Services to be consumed by pl/sql code within the database.

  • Thanks @Anthonyaccioly I ended up opting to expose web services, it was less "boring" to do. But anytime I will try to redo setting up classpath.

  • Did you find a solution? Poste as an answer to help other people.

1 answer

1


@Ericosouza sure this compiled outside of Oracle? For example, this:

public class Importar
 import org.pentaho.di.trans.Trans;
 import org.pentaho.di.trans.TransMeta;

I believe that if it works with the simple example class, then the error is its class. The correct one would not be?

import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;

public class Importar{
//...
}

The imports must be before class definition and the class must open { and close }.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.