Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to call OS commands by java stored procedures

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how java stored procedures call OS commands, I believe most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1. Take a look at this catalog first.

[oracle@ocean ~] $pwd

/ home/oracle

[oracle@ocean ~] $ls-l

Total 8

-rw-r--r-- 1 oracle orains 604 Dec 26 2006 bash

two。 Connect to test user

SQL > conn test/test

Connected.

3. Permissions granted to test users to read and write files and execute commands

SQL > exec dbms_java.grant_permission ('TEST','SYS:java.io.FilePermission','','read,write,execute,delete')

PL/SQL procedure successfully completed.

SQL > exec dbms_java.grant_permission ('TEST','java.lang.RuntimePermission','*','writeFileDescriptor')

PL/SQL procedure successfully completed.

4. Set up the java stored procedure. Note that the path of the exp and the path of the dmp file here are the path of the database server.

Create or replace and compile java source named "aa"

As

Import java.io.*

Import java.lang.*

Import java.util.*

Import java.sql.*

Import oracle.sql.*

Public class aa

{

Public static void invoke_exe () throws IOException

{

Process p=Runtime.getRuntime () .exec ("/ oracle/product/9.2.4/bin/exp userid=test/test file=/home/oracle/test.dmp")

Try

{

P.waitFor ()

} catch (InterruptedException ie) {System.out.println (ie);}

}

}

/

Java created.

Elapsed: 00:00:00.01

5. Establish a stored procedure call_aa that calls the java stored procedure

Create or replace procedure call_aa

As language java

Name 'aa.invoke_exe ()'

/

6. Execute java stored procedures

Exec call_aa

7. Check to see if the dmp file has been generated

[oracle@ocean ~] $pwd

/ home/oracle

[oracle@ocean ~] $ls-l

Total 28

-rw-r--r-- 1 oracle orains 604 Dec 26 2006 bash

-rw-r--r-- 1 oracle orains 16384 Jul 3 14:12 test.dmp

-

Exec dbms_Java.Grant_Permission ('TEST',' java.io.FilePermission',', 'read, write, execute, delete')

Exec dbms_Java.Grant_Permission ('TEST',' java.io.FilePermission','d java.io.FilePermission', aa.battering, 'read, write, execute, delete')

Exec dbms_java.grant_permission ('TEST','java.lang.RuntimePermission','*','writeFileDescriptor')

These are all the contents of the article "how to call OS commands by java stored procedures". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report