'SP2-0310: unable to open file .sql

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

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 :

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.

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



Solution 1:[1]

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 .bat manually 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.

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

Solution 2:[2]

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"

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.

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/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 user3065757