Oracle stored Procedures under Java (detailed) 1th/3 page _jsp programming

Source: Internet
Author: User
Any reprint, please respect the copyright. (Author: Iihero on CSDN)
How do I create a Java stored procedure?
There are usually three ways to create a Java stored procedure.
1. Use Oracle SQL statements to create:
e.g. using create or replace and compile Java source named "<name>" as
Follow the Java source program behind. The method that requires the class must be public static to be used for stored procedures.
Copy Code code as follows:

Sql> Create or replace and compile Java source named "Javademo1"
2 AS
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 mistakes.

sql> Create or Replace procedure Javademo1
2 AS
3 language Java name ' Javademo1.main (java.lang.string[]) ';
4/

Procedure has been created.

Sql> set Serveroutput on
Sql> call Javademo1 ();

Call complete.

Sql> call Dbms_java.set_output (5000);

Call complete.

Sql> call Javademo1 ();
Hello, Java demo1

Call complete.

Sql> call Javademo1 ();
Hello, Java demo1
Call complete.

2. Use an external class file to mount the creation
e.g. now that the external file is used, it is necessary to place the class file below a directory in Oracle server.
Copy Code code 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;

The authorization was successful.

Sql> Conn Scott/tiger@iihero.oracledb
is 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/

Procedure has been created.

Sql> call Testjavaproc ();

Call complete.

Sql> Execute Testjavaproc;

The PL/SQL process has completed successfully.

Sql> set serveroutput on size 5000
Sql> call Dbms_java.set_output (5000);

Call complete.

Sql> Execute Testjavaproc;
It ' s a Java Oracle procedure.

Current 1/3 page 123 Next read the full text
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.