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?
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.
– Anthony Accioly
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 Souza
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.
– Anthony Accioly
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.
– Erico Souza
Did you find a solution? Poste as an answer to help other people.
– Maniero