Oracle calls Java external stored procedures

Source: Internet
Author: User

1. Write Java

2. Use loadjava to import the database. loadjava is under $ Oracle_HOME/bin.

Loadjava-u <user>/<passwd >@< tns>-resolve-v <java file>

This method loads sourcecode into the database.

If you have previously loaded the same java program, you must first drop

Dropjava-u <user>/<passwd >@< tns>-v <java file>

3. Check that the java database has been imported

Select * from user_source where type LIKE 'java % 'and name =' <JAVA file>'

4. Create a function

Create or replace function <FUNCTION_NAME> (<parameter list in oracle datatype>) RETURN <oracle datatype of return variable>
LANGUAGE JAVA
Name' <clase. method> (<parameter list in java datatype>) return java datatype of return variable ';

Appendix:

If you need java to access files, you must use the dba user to grant permissions.

EXEC Dbms_Java.Grant_Permission ('onboarding ', 'sys: java. lang. runtimepermission', 'writefiledescriptor ','');
EXEC Dbms_Java.Grant_Permission ('onboarding ', 'sys: java. lang. runtimepermission', 'readfiledescriptor ','');
EXEC dbms_java.grant_permission ('onboarding ', 'sys: java. io. filepermission',' <all files> ', 'execute ');


The statement for revoking permissions is as follows:

EXEC Dbms_Java.revoke_Permission ('onboarding ', 'sys: java. lang. runtimepermission', 'writefiledescriptor ','');
EXEC Dbms_Java.revoke_Permission ('onboarding ', 'sys: java. lang. runtimepermission', 'readfiledescriptor ','');
EXEC dbms_java.revoke_permission ('onboarding ', 'sys: java. io. FilePermission', '<all files>', 'execute ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.