INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to handle string array returned from Java function in PL/SQL...?

How to handle string array returned from Java function in PL/SQL...?

How to handle string array returned from Java function in PL/SQL...?

(OP)
Hi

I've got a function in Java that returns a string array but I'm not sure how to reference this in PL/SQL (I am a total beginner when it comes to Java!). The Java function is as follows:

CODE

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "GetDirListArray" AS
    import java.io.*;
    import java.sql.*;

    public class GetDirListArray
    {
        public static String[] getList(String directory)
                           throws SQLException
        {
            File path = new File( directory );
            return (path.list());
        }
    }

What I want to do is use this function from within a PL/SQL program. I've created a type in Oracle as follows (to handle the string array returned by the Java function):

CODE

CREATE OR REPLACE TYPE typDirList IS TABLE OF VARCHAR2(200)

I've then tried to create an Oracle function for the Java function:

CODE

CREATE OR REPLACE FUNCTION get_dir_list_array(p_directory IN VARCHAR2) RETURN typDirList AS LANGUAGE JAVA
   NAME 'GetDirListArray.GetList( java.lang.String )';

But when I run this I get:

CODE

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

Can someone give me any pointers as to what I'm doing wrong? Or even if what I'm trying to do is possible!

Many thanks

RE: How to handle string array returned from Java function in PL/SQL...?

(OP)
OK, I just realised that I forgot to include a return type for the Java function....doh!

Altered to:

CODE

CREATE OR REPLACE FUNCTION get_dir_list_array(p_directory IN VARCHAR2) RETURN typDirList AS LANGUAGE JAVA
   NAME 'GetDirListArray.GetList( java.lang.String ) return String[]';

Compiles OK now...surprisingly!

No idea if it will work though - that's the next task!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close