Oracle Apex and java classes

158 Views Asked by At

I am new to oracle apex and I need to call java classes through oracle apex database stores procedures but I have no idea how to do this, any clues?

having a "step by step" link about how to do so would be great if possible, its not that easy to work on DB inside apex itself that's why I need a detailed description for steps required.

calling java classes is mandatory for our project, we couldn't avoid.

thanks,

1

There are 1 best solutions below

1
Connor McDonald On

Java classes in the database are wrapped by a PL/SQL layer, so calling a Java class (from APEX) will be no different to calling a PL/SQL procedure, eg

SQL> create or replace and compile
  2  java source named "demo_passing_pkg"
  3  as
  4  import java.io.*;
  5  import java.sql.*;
  6  import java.math.*;
  7  import oracle.sql.*;
  8  import oracle.jdbc.driver.*;
  9
 10  public class demo_passing_pkg extends Object
 11  {
 12
 13  public static void pass( java.lang.String[] p_str, java.lang.Double[] p_num )
 14  {
 15          p_str[0] = p_str[0] + "Hello World";
 16          p_num[0] = new Double( 55 );
 17  }
 18
 19  }
 20  /
 
Java created.

SQL> create or replace package demo_passing_pkg
  2  as
  3      procedure pass( p_string in out varchar2, p_double in out number )
  4      as
  5      language java
  6      name 'demo_passing_pkg.pass( java.lang.String[], java.lang.Double[] )';
  7
  8  end demo_passing_pkg;
  9  /
 
Package created.
 
 
SQL> variable s varchar2(255)
SQL> variable n number
SQL> set autoprint on
SQL> exec :s := 'test '; :n := 42;
 
PL/SQL procedure successfully completed.
 
 
         N
----------
        42
 
 
S
-------------------------------------------------------------------------------
test
 
SQL> exec demo_passing_pkg.pass( :s, :n )
 
PL/SQL procedure successfully completed.
 
 
         N
----------
        55
 
 
S
-------------------------------------------------------------------------------
test Hello World