Skip to Main Content
  • Questions
  • Problem executing an OS Command via Java Function - remote connections only

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Ginny.

Asked: March 10, 2016 - 5:25 pm UTC

Last updated: March 11, 2016 - 2:11 am UTC

Version: 11.2.0.4

Viewed 1000+ times

You Asked

Hi Tom,

I'm hoping you can help me solve this issue. I think it's related to environment variables, but I can't figure out what to look at.

I have a java function compiled into the database that executes a shell script out on the server. The server is running RHEL 5.

I have the appropriate PL/SQL "wrapper" written so that we can call the function directly from PL/SQL. We've executed the grants to the user so that they have permissions to the file on the server.

So, when I try to execute the function (SELECT BANINST1.callAwrun('TEST_JOB') FROM DUAL;) it works great from sqlplus if I'm on the server. However, if I try to execute it from PL/SQL Developer on my machine (or even from sqlplus on a different server using a remote connection to the database), it doesn't actually execute the shell script. It's not giving us any Oracle or Java errors, it just returns NULL for the select statement (it's supposed to return the ID of the job that's been fired in our automation software).

Also, as further background, I have a test instance that's a clone of the database on a separate server. On that database/server, all of this works fine whether I'm in a local or remote SQL connection.

Can you offer any suggestions?

Thanks,
Ginny Donovan

and Connor said...

Try a 10046 trace on an execution.

eg, I created a basic run_host_command java as per examples on AskTom, and then did:

SQL> alter session set events = '10046 trace name context forever, level 12';
SQL> exec rc('C:\bin\ffmpeg\bin\ffmpeg.exe')

PL/SQL procedure successfully completed.


But in the trace file, I see this:

java.security.AccessControlException: the Permission (java.io.FilePermission C:\bin\ffmpeg\bin\ffmpeg.exe execute) has not been granted to MCDONAC. The PL/SQL to grant this is dbms_java.grant_permission( 'MCDONAC', 'SYS:java.io.FilePermission', 'C:\bin\ffmpeg\bin\ffmpeg.exe', 'execute' )

 at java.security.AccessControlContext.checkPermission(AccessControlContext.java)

 at java.security.AccessController.checkPermission(AccessController.java)

 at java.lang.SecurityManager.checkPermission(SecurityManager.java)

 at oracle.aurora.rdbms.SecurityManagerImpl.checkPermission(SecurityManagerImpl.java)



So check the trace file - it might give you some leads.

If that doesn't help, then add as much debugging into the the PL/SQL *and* the Java (eg write to debug file) as possible, and see what you can track down.

Hope this helps.

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library