Question

Sometime this weekend one of our databases (11.1.0.7) began having problems accessing certain folders on a portion of the network through Java. I have reproduced the problem using a small portion of java that does nothing but create a file object and attempt to delete the file. From the database this works for deleting local files and deleting network files on our \zion\dp\ share, but not from our \zion\it\ share.

We have another database that runs under the same domain users account that has no problems deleting files from this location. Also logged in as the same domain user on the server having problems I can run the java outside of Oracle and have no problems deleting files. The domain user has full control over the folder and logged in as the user I can create, modify, and delete files.

If I haven't granted my oracle database user the appropriate dbms_java permissions I get the appropriate java.security.AccessControlException error. After I grant the permission the java runs to completion, the delete command returns false (nothing deleted) and the file is not deleted.

I opened a case with Oracle, but it looks like they aren't going to help any more because it involves file commands being run from the java layer even though it is only reproducible from the Oracle environment.

Test Code:

import java.io.*;               
import java.sql.*;                 
import java.util.*;             

public class Ajclass
{
   public static void ajprocedure(String pdfFileName) throws Exception
   {
      boolean result;
      try {
         System.out.println("Start!");

         File file = new File(pdfFileName);
         //result = file.delete();
         result = file.exists();
         if (result == true) 
           System.out.println("xxFile deleted.");
         else
           System.out.println("xxFile NOT deleted!");
         System.out.println("End!");
      } catch ( Exception e ) {
         throw(e);
      }         
   }
}

Other code I recently found to be failing only against this share and only when run from inside this database:

import java.io.*;
import java.sql.*;

public class DirectoryListing
{
public static void getList(String directory) throws SQLException
   {
      File path = new File( directory );
      String[] list = path.list();
      String element;
      int CurrentFile;

      for(CurrentFile = 0; CurrentFile < list.length; CurrentFile++)
      {
        element = list[CurrentFile];
        #sql { INSERT INTO DIRECTORYLISTING (FILENAME) VALUES (:element) };
      }
   }
}
Was it helpful?

Solution 5

Oracle support suggested restarting the server after looking at the results of Process Monitor being run on the oracle executable while the delete/exist operation was taking place. They found that the action gets a result of STATUS_USER_SESSION_DELETED (0xC0000203) from the remote server, which means the communication between the local and remote server are not working correctly on a windows level. We plan to restart this weekend to see if that fixes the problem.

OTHER TIPS

Commands run against the OS from inside the database run as the oracle account. So you need to grant read and write on \zion\it\ at the OS level to oracle as well as granting the Java permissions within the database.

Is deleting files what you actually want to do? Or is it just a test? Because we can delete files using the PL/SQL procedure UTL_FILE.FREMOVE().

If you have oracle admin permissions, Check your remote server (other domain server) host name and Port is available under Oracle Listeners list ?? (using Oracle Netmanager) and also check listener.ora file..

"but create a file object and attempt to delete the file" Can you determine if the delete fails because a) It can't find the file Something odd in the file name b) The file is locked / open by another process Might there be something looking at that share (replication, backup, virus scan) c) Insufficient permission

What are the underlying file systems ?

How about posting the entire code chunk. Another forum suggests that you might not be able to use the same filehandle. "But I'd be willing to bet that you are trying to delete the file based on the variable 'handle' of the FileOutputStream. If that's the case, you can't; you need to create a File Object using the name of the file used when creating the FileOutputStream, and then delete() that."

The fact that it works in some cases might be 'luck' rather than documented behavior.

PS. using the delete method of a path rather than file looks like a failure will be more informative.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top