Thursday, November 5, 2009

How to call a Java Stored Procedure from PL/SQL Procedure

Below is an example to call a Java Stored Procedure from PL/SQL Procedure

1. Define a Java Stored Stored procedure as below in the database.

DROP JAVA SOURCE APPS."DirList";

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED apps."DirList" AS import java.io.*;
import java.sql.*;
public class dirlist
{
public static void getlist(string directory)
throws sqlexception
{
try
{
file path = new file( directory );
string[] list = path.list();
string element;
for(int i = 0; i < list.length; i++)
{
element = list[i];
#sql { insert into xx_dir_list (filename)
values (:element) };
} catch (exception e);
{
system.out.ptintln(e.getmeaasage);
}
}
}
}


2. Call the above Java Stored Stored procedure "DirList" from the PL/SQL Procedure as follows.

CREATE OR REPLACE PROCEDURE APPS.get_dir_list (p_directory IN VARCHAR2)
AS
LANGUAGE JAVA
NAME 'DirList.getList( java.lang.String )';
/

No comments:

Post a Comment