Oracle calls external java program code

Source: Internet
Author: User

 

Software environment:

1. Operating System: win xp

2. Database: oracle 10.2

3. installation path: d: \ oracle

4. test the class Directory: d: \ test

Premise: If you use an external call to the java program, make sure that the jdk under the oracle installation directory is consistent with the jdk version compiled by you. Otherwise, the system reports that the class cannot be found. At the same time, ensure that the class file is stored in the hard disk of the database server.

Implementation Method:

1. Create a java file: OraclejavaProc. java

 

1 public class OraclejavaProc {

2 public static void main (String [] args ){

3 System. out. println ("It's a oraclejavaproc! ");

4}

5}

 

2. Use D: \ oracle \ product \ 10.2.0 \ db_1 \ jdk \ bin javac in the oracle directory to compile

Javac OraclejavaProc. java

3. Test the java OraclejavaProc function to test whether information can be output successfully.

4. log on to oracle (SQL * plus or plsql can be used)

 

1 SQL> conn system/manager

2 SQL> grant create any directory to scott; -- authorize

3 SQL> conn scott/tiger --- skip this step if the Administrator logs on.

4 SQL> create or replace directory oracle_dir as 'd: \ test ';

5 -- the directory has been created.

6 SQL> create or replace java class using bfile (oracle_dir, 'oraclejavaproc. class ');

7. Java has been created.

8 -- SQL> select object_name, object_type, STATUS from user_objects; -- check whether object_type has java class data.

9 SQL> create or replace procedure oracle_java as language java

10 name 'oraclejavaproc. main (java. lang. String []) ';

11 -- the process has been created.

12 SQL> set serveroutput on size 5000 -- When pl/SQL is used, this sentence can be printed or not.

13 SQL> call dbms_java.set_output (5000 );

14 -- The call is complete.

15 SQL> execute oracle_java;

16 It's a oraclejavaproc!

17

18 The PL/SQL process has been completed successfully.

19 SQL> call test_java ();

20 It's a oraclejavaproc!

21

22 -- the call is complete.

 

 

 

Author coffee doll

Related Article

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.