Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Using Java Blocks Can Anyone Help?
Jay ,
You need a java class loaded into database Which
runs OS Commands (or .bat file) . For this look at below... ...
Hope this helps . (But I could not manage to run OS
commands deleting files from network altough shared.But locally it works
fine.)
Bunyamin K.
Karadeniz Oracle
DBA / DeveloperCivilian IT DepartmentHavelsan A.S. Eskisehir yolu
7.km Ankara TurkeyPhone: +90 312 2873565 / 1217
Step1. compile the java code
javac program_name.java
This operation is used to generate related class. Do not need to recompile java code, if the related class is exists. Step2. Load generated class into the Database loadjava –u user_name/password_at_connection_name program_name.class
Example : Call an OS command from a Java stored procedure (JSP)<FONT face="Courier New" size=2>
-------------------code begins here------------------------------------ import java.lang.Runtime; import java.lang.Process;
} } } -----------------code ends here------------------------------------------You can write this code with any editor and save it as "executecmd.java ". Then compile this code.
set PATH=%PATH%; path_name
compile the program
javac program_name.java
After compile operation you can load this codes into the database and execute
it as described above.
NOTE : Some permissions are necessary to execute java codes into the
database, this operations can be made as follows :
- connect database with system manager (conn
sys/password_at_connectionname )
- set serveroutput on
- call dbms_java.grand_permission(username,permissionname, filename,
permissions)
call
dbms_java.grand_permission(‘user’,’java.io.filePermission’,’*’,’read,write,execute’)
call
dbms_java.grand_permission(‘user’,’java.lang.runtimePermission’,’*’,writeFileDescriptor’)
…..
- commit
- log of and reconnect as the specified user
You can also give all permissions to the specified user with this command
:
grant JAVASYSPRIV to username
if no permissions are given to the user, the procedure are not executed
correctly.
<BLOCKQUOTE
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
To: <A href="mailto:ORACLE-L_at_fatcity.com"
title=ORACLE-L_at_fatcity.com>Multiple recipients of list ORACLE-L
Sent: Monday, January 28, 2002 1:55
PM
Subject: OT: Using Java Blocks Can Anyone
Help?
<FONT face="Times New Roman"
size=3>hello: Can you run a Java Store Procedure as an anonymous
block? I'm trying to do as suggested and use Java to delete an
operating system file (Win2k/NT). The only issue is that this must be
executed in script format without storing any objects or references
in the database. Since I am using 8.1.6I figured that I
might be able to do it all as a sql file with anonymous
Java blocks. Can this be done? If do does anyone have an
example of the syntax that would be needed to delete a file from a
passed parameter? I'vestarted experimenting with the below
but so far have been unsuccessful, in getting the block to
execute. Unfortunately I know very little Java so any help
or directory would be greatly
appreciated. Begin
public class Hello
{
Code*/
{
tail;