Java Mailing List Archive

http://www.dba.5341.com/

Home » Home (12/2007) » oracle l »

Java external procedure help?

Robert Freeman

2006-06-11

Replies:

I'm trying to create an external java procedure and call it from within
Oracle. I've already created a very basic procedure and everything works
fine, so I am fairly certain the Oracle configuration is ok.

Here is the java:

import java.io.*;
class FileOutputDemo
{
    public static void main(String args[])
    {
          FileOutputStream out; // declare a file output object
          PrintStream p; // declare a print stream object
          try
          {
               // Create a new file output stream
               // connected to "myfile.txt"
               out = new FileOutputStream("myfile.txt");
               // Connect print stream to the output stream
               p = new PrintStream( out );
               p.println ("This is written to a file");
               p.close();
          }
          catch (Exception e)
          {
               System.err.println ("Error writing to file");
          }
    }
}

I can compile this, and I can run it from the OS. I then try to set it up in
Oracle so I can call it externally:

SQL> create directory j_dir as 'c:/java';
SQL> create java class using bfile (j_dir, 'FileOutputDemo.class');

These steps all work ok.

When I try to create the procedure I get an error.
Here is the call to create the java stored procedure:

Create or replace procedure test_write
is
language java
name 'FileOutputDemo(java.lang.String)';

And this is the error being returned:

Warning: Procedure created with compilation errors.

SQL> show err
Errors for PROCEDURE TEST_WRITE:

LINE/COL ERROR
-------- ---------------------------------------------------------
0/0    PL/SQL: Compilation unit analysis terminated
4/1    PLS-00311: the declaration of
     "FileOutputDemo.main(java.lang.String)" is incomplete or
     malformed

I'm sure I'm defining the class incorrectly somehow. Can someone help me
please?

Robert

--
http://www.freelists.org/webpage/oracle-l


©2008 dba.5341.com - Jax Systems, LLC, U.S.A.