Thursday, March 22, 2012

Calling Java Application from PL/SQL code

Colleagues,

I am not an expert in PL/SQL neither Java, so I require a help here:

What I am planning to do is to use PL/SQL to call a Java application (pass 3 arguments).

The Java application is used to make call to an API that resides on a Bea Weblogic application/web server (its not used to access database).

I got already the PL/SQL Trigger, but I need to add to it the call to the Java application (the Java application already exists)

Simply, would any one provide an example of how to make that call.

Do I need to load Java classes into the Oracle database or not?

I am using Oracle 9i database, and the Java application is compiled using Java SDK 1.4.2

Many thanksHi,

To call java class from a pl/sql, you need to follow the steps.

1. First create a java file and compile it.

2. Load the java class file to the database using 'loadjava' utility.

Ex: loadjava -u scott/tiger abc.class

3. Create a pl/sql wrapper aroung the java class like

CREATE OR REPLACE PROCEDURE test (a1 VARCHAR2) AS LANGUAGE JAVA name 'abc.main(java.lang.String[])';

4. Then execute the stored procedure

exec test(<input>);|||HI,

Invoking the java stored procedures from any PL/SQL block or stored module works the same way it would for any other PL/SQL stored function.

For example:

SQLPLUS> set serveroutput on size 5000;

SQLPLUS> declare
2> temp varchar2(100);
3> begin
4> temp := ConcatTwo('Hello','World');
5> DBMS_OUTPUT.PUT_LINE(temp);
6> end;
7> /|||Thanks... suneel.kumar and satish_ct

you realy give me some ideas...|||These examples provide the capability to load specific "classes" to the
database and most will work however Oracle will have problems with
classes that import from GUI packages such as AWT or Swing.|||HI,

Did U come across any such error?|||My class is only initiate a request or call to another system API (my class doesn't import from any GUI Packages).

Many thanks to you all|||when I've tried to load the java class, but I got the following error:

ORA-04031: unable to allocate 4032 bytes of shared memory ("shared pool","unknown object","joxs heap init","ioc_allocate_pal")

would some one told me what I should do.

I think that the shared pool is out of memory so should I consult the DBA, system Admin or is it from my PC, where I am making a conection to the server/Database.

No comments:

Post a Comment