Goal: Read a directory path for a specific file and return TRUE if the file exists or FALSE if file not found (Boolean value). I am not experienced using Java so please forgive the mistakes. I realize that I am not attempting to return a Boolean value from the Java source because I could not get that to work and had hoped I would be able to get a varchar to return; however, neither work and I am now receiving ORA-29531 when executing. Any help you can provide will be greatly appreciated.
Coded in SQLDeveloper against Oracle Database 11g Release 11.2.0.3.0 - 64bit.
I have created a PL/SQL Function to call a Java class:
CREATE OR REPLACE FUNCTION dir_file(p_directory in varchar2, p_file in varchar2)
RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'TempDirFile.getFileList( java.lang.String, java.lang.String ) return java.lang.String';
CREATE OR REPLACE
AND COMPILE JAVA SOURCE NAMED "TempDirFile"
AS
import java.io.File;
import java.sql.*;
import java.io.FilenameFilter;
public class TempDirFile
{
public static void getList(String args)
throws SQLException
{
File[] fileList = getFileList( args );
for(File file : fileList) {
System.out.println(file.getName());
}
}
public static File[] getFileList(String dirPath)
{
File dir = new File(dirPath);
File[] fileList = dir.listFiles(new FilenameFilter()
{
public boolean accept(File dir, String name) {
return name.matches( name );
}
});
return fileList;
}
}
/
Anonymous block I am using to execute:
DECLARE
v_file VARCHAR2(255);
BEGIN
v_file := ntcinternalsys.dir_file('path','filename');
dbms_output.put_line('v_file = '||v_file); -- to see if there is anything returned.
END;
Error report -
ORA-29531: no method getFileList in class TempDirFile
ORA-06512: at "NTCINTERNALSYS.DIR_FILE", line 1
ORA-06512: at line 4
29531. 00000 - "no method %s in class %s"
*Cause: An attempt was made to execute a non-existent method in a
Java class.
*Action: Adjust the call or create the specified method.