简体   繁体   English

Oracle数据库使用Java删除文件

[英]Oracle Database Deleting Files Using Java

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. 这个周末的某个时候,我们的数据库之一(11.1.0.7)开始无法通过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. 我使用一小部分Java重现了该问题,该Java除了创建文件对象并尝试删除文件外,什么也不做。 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. 从数据库中,这可用于删除\\ zion \\ dp \\共享上的本地文件和网络文件,但不适用于\\ zion \\ it \\共享中的文件。

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. 还以服务器上的同一域用户身份登录时遇到问题,我可以在Oracle外部运行Java,并且删除文件没有问题。 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. 如果尚未授予我的oracle数据库用户适当的dbms_java权限,则会收到适当的java.security.AccessControlException错误。 After I grant the permission the java runs to completion, the delete command returns false (nothing deleted) and the file is not deleted. 在我授予Java运行权限以完成操作后,delete命令将返回false(不删除任何内容),并且不会删除该文件。

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. 我为Oracle开了一个案子,但看起来他们将无济于事,因为它涉及从Java层运行的文件命令,即使它只能在Oracle环境中再现。

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) };
      }
   }
}

Commands run against the OS from inside the database run as the oracle account. 从数据库内部针对操作系统运行的命令以oracle帐户身份运行。 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. 因此,您需要在操作系统级别上授予对oracle \\ zion \\ it \\ 上的读写权限,以及授予数据库中的Java权限。

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() . 因为我们可以使用PL / SQL过程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 ?? 如果您具有oracle管理员权限,请检查您的远程服务器(其他域服务器)的主机名,并且Oracle侦听器列表下的端口是否可用? (using Oracle Netmanager) and also check listener.ora file.. (使用Oracle Netmanager),并检查listener.ora文件。

"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 “但是创建一个文件对象并尝试删除该文件”您能确定删除是否失败,因为a)找不到文件名文件中有些奇怪b)文件被另一个进程锁定/打开了可能查看该共享的内容(复制,备份,病毒扫描)c)权限不足

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." “但是我敢打赌,您正在尝试根据FileOutputStream的变量'handle'删除文件。如果是这种情况,则不能;您需要使用文件名创建一个File对象。创建FileOutputStream时使用的文件,然后将其删除()。”

The fact that it works in some cases might be 'luck' rather than documented behavior. 它在某些情况下有效的事实可能是“运气”,而不是有据可查的行为。

PS. PS。 using the delete method of a path rather than file looks like a failure will be more informative. 使用路径而不是文件的delete方法看起来像失败会更有帮助。

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. Oracle支持建议在执行删除/存在操作时查看在oracle可执行文件上运行的Process Monitor的结果后,重新启动服务器。 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. 他们发现该操作从远程服务器获得STATUS_USER_SESSION_DELETED (0xC0000203)的结果,这意味着本地和远程服务器之间的通信在Windows级别上无法正常工作。 We plan to restart this weekend to see if that fixes the problem. 我们计划在本周末重新开始,以查看是否可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM