Java-based Oracle Stored Procedure (detailed description) page 1/3

Source: Internet
Author: User

Respect copyright for any reposted content. (Author: iihero on csdn)
1. How to Create a java stored procedure?
There are usually three methods to create a java stored procedure.
1. Use oracle SQL statements to create:
E.g. Use create or replace and compile java source named "<name>"
Keep up with the java source program. The class method must be public static before it can be used for stored procedures.
Copy codeThe Code is as follows:
SQL> create or replace and compile java source named "javademo1"
2
3 import java. SQL .*;
4 public class JavaDemo1
5 {
6 public static void main (String [] argv)
7 {
8 System. out. println ("hello, java demo1 ");
9}
10}
11/

Java has been created.

SQL> show errors java source "javademo1"
No error.

SQL> create or replace procedure javademo1
2
3 language java name 'javademo1. main (java. lang. String []) ';
4/

The process has been created.

SQL> set serveroutput on
SQL> call javademo1 ();

The call is complete.

SQL> call dbms_java.set_output (5000 );

The call is complete.

SQL> call javademo1 ();
Hello, java demo1

The call is complete.

SQL> call javademo1 ();
Hello, java demo1
The call is complete.

2. Use an external class file to load and create
E.g. Since external files are used, the class files must be placed under a directory of oracle Server.
Copy codeThe Code is as follows:
Public class OracleJavaProc
{
Public static void main (String [] argv)
{
System. out. println ("It's a Java Oracle procedure .");
}
}


SQL> grant create any directory to scott;

Authorization successful.

SQL> conn scott/tiger@iihero.oracledb
Connected.
SQL> create or replace directory test_dir as 'd: \ oracle ';

The directory has been created.

SQL> create or replace java class using bfile (test_dir, 'oraclejavaproc. class ')
2/

Java has been created.

SQL> create or replace procedure testjavaproc as language java name 'oraclejavaproc. main (java. lang. String []) ';
2/

The process has been created.

SQL> call testjavaproc ();

The call is complete.

SQL> execute testjavaproc;

The PL/SQL process is successfully completed.

SQL> set serveroutput on size 5000
SQL> call dbms_java.set_output (5000 );

The call is complete.

SQL> execute testjavaproc;
It's a Java Oracle procedure.

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.