Java SP2-0310:无法打开文件 .sql

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20375222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 01:28:47  来源:igfitidea点击:

SP2-0310: unable to open file .sql

javaoracle

提问by user3065757

I am calling batch file from my java program which in result execute some .sql files. the batch script is below:

我正在从我的 java 程序调用批处理文件,结果执行一些 .sql 文件。批处理脚本如下:

set part1= CREATE OR REPLACE DIRECTORY REPORT AS '
set total=%part1%%4';
echo %total% > DIR_REPORT.sql
echo exit; >>DIR_REPORT.sql
sqlplus %1/%2@%3 @./DIR_REPORT.sql
sqlplus %1/%2@%3 @./PACKAGE_SCRIPTv2.sql

and my java code is :

我的java代码是:

Runtime run = Runtime.getRuntime();
System.out.println("Start Running the batch file");
Process p = run.exec(new String[]{"cmd.exe","/c", "start", "C:/Users/sony/Documents/NetBeansProjects/CodeReview/src/codereview/install.bat",i,j,m,l});
System.out.println("Completed");

it is giving error:

它给出了错误:

SP2-0310: unable to open file

The first file generated using the batch (DIR_REPORT) is being executed but my PACKAGE_SCRIPTv2.sql is not being executed but raises error, please help me what to do.

正在执行使用批处理 (DIR_REPORT) 生成的第一个文件,但我的 PACKAGE_SCRIPTv2.sql 没有被执行但引发错误,请帮助我该怎么做。

although when a run batch file mannualy from cmd everything works fine...

虽然当从 cmd 手动运行批处理文件时一切正常......

回答by Alex Poole

The first script is being created and executed in the current working directory, so it will always exist (assuming you have permission to create there). The second is expected to be in the current working directory as well. The question is, then, what is the current working directory?

第一个脚本正在当前工作目录中创建和执行,因此它将始终存在(假设您有权在那里创建)。第二个也应该在当前工作目录中。那么问题来了,当前的工作目录是什么?

It looks like you're expecting it to be C:/Users/sony/Documents/NetBeansProjects/CodeReview/src/codereview/, and if you run the .batmanually there it works OK (from what you've said); so when you call it from Java it must be somewhere else. That will either be whatever the working directory was when your JVM launched, or your home directory, I think - not quite sure.

看起来您希望它是C:/Users/sony/Documents/NetBeansProjects/CodeReview/src/codereview/,如果您在.bat那里手动运行它,它就可以正常工作(根据您所说的);所以当你从 Java 调用它时,它必须在其他地方。这将是您的 JVM 启动时的任何工作目录,或者您的主目录,我认为 - 不太确定。

You need to specify the correct directory, either hard-coded into the script, or passed as another parameter. You may then want to cdto that in your script so the DIR_REPORT.sqlis created in the same, known, place; otherwise you can use it create the full path to PACKAGE_SCRIPTv2.sql.

您需要指定正确的目录,或者硬编码到脚本中,或者作为另一个参数传递。然后,您可能希望cd在脚本中使用它,以便DIR_REPORT.sql在相同的已知位置创建;否则,您可以使用它创建到PACKAGE_SCRIPTv2.sql.

回答by user3065757

yeah the problem is path defined in statement contains all the files but while execution the script is going only till :

是的,问题是在语句中定义的路径包含所有文件,但是在执行时,脚本只会运行到:

"C:/Users/sony/Documents/NetBeansProjects/CodeReview"

“C:/Users/sony/Documents/NetBeansProjects/CodeReview”

This is what was displayed in cmd, so I have placed the file into this directory and it started working...don't know the reason.

这是在cmd中显示的内容,所以我已将文件放入此目录并开始工作......不知道原因。

TIP: when you find such kind of issue please look at the error message properly as it will tell you where the script is looking when it got failed, so just place the file at that location and will work...

提示:当您发现此类问题时,请正确查看错误消息,因为它会告诉您脚本失败时的位置,因此只需将文件放在该位置即可...

Enjoy \m/

享受\m/