简体   繁体   English

如何使用Java存储过程打开文件

[英]How can I open a file using java stored procedure

I am using oracle database 10g. 我正在使用oracle数据库10g。 I have to write a java stroed procedure through which i can call a file at the server and store it locally at the users machine. 我必须编写一个Java程序,通过它我可以在服务器上调用文件并将其本地存储在用户计算机上。 Im using oracle Apex 3.1.1. 我正在使用oracle Apex 3.1.1。

If you're talking about a true Oracle Java stored procedure, I don't think you can do this. 如果您在谈论真正的Oracle Java存储过程,那么我认为您不能这样做。 Remember that the Java procedure is running under the Oracle JVM in the database, which means that it can only "see" the database host filesystem. 请记住,Java过程在数据库中的Oracle JVM下运行,这意味着它只能“查看”数据库主机文件系统。

Why a Java Stored Procedure? 为什么要使用Java存储过程? Just because you think it cannot be done in PL/SQL? 仅仅因为您认为它不能在PL / SQL中完成?

There are a couple of FTP implementations in PL/SQL. PL / SQL中有几个FTP实现。 Sourceforge has one . Sourceforge有一个 Tim Hall has published one on his Oracle-Base site . 蒂姆·霍尔(Tim Hall)在他的Oracle-Base网站上发布了一篇。

1 : http://sourceforge.net/projects/plsqlftp/ "UTL_FTP project 1http//sourceforge.net/projects/plsqlftp/ “ UTL_FTP项目

Any reason it has to be java? 任何原因都必须是Java? DBMS_FILE in PL/SQL should generally work fine. PL / SQL中的DBMS_FILE通常应该可以正常工作。

Otherwise, I think ( I haven't done java stored procedures for a long time ) you should just be able to open an IO stream as you always would in java. 否则,我认为(我已经很长时间没有做过Java存储过程了),您应该只能像在Java中一样一直打开IO流。

Since you are using APEX 3.1, is there a reason why you can simply create a link to the file on the server through APEX (hence the Web Server) to download the file? 由于您使用的是APEX 3.1,因此,为什么可以通过APEX(因此是Web服务器)在服务器上简单地创建指向文件的链接以下载文件?

You can also do this through UTL_FILE package, just don't forget to run the CREATE DIRECTORY and grant READ on the directory first. 您也可以通过UTL_FILE包来执行此操作,只是不要忘记运行CREATE DIRECTORY并首先在目录上授予READ。

I think you can do the file open through java as well, but only if you do the grant first to allow the Oracle process access to the directories on your system. 我认为您也可以通过java打开文件,但前提是您必须先进行授予才能允许Oracle进程访问系统上的目录。 This does seem like the most complex method. 这似乎是最复杂的方法。

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

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