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