Release Java programs in Oracle

Source: Internet
Author: User
Java programs or classes can be stored in the database and replaced or supplemented with PL/SQL. Java can be used as a database trigger, stored procedure, function, and object member function. After developing a Java stored procedure according to the following procedure, you can call the Java stored procedure from SQL or PL/SQL, just like calling a common PL/SQL process. The following code describes how to develop and use a Java program that outputs "Hello, world" in SQL * Plus:
1.Write the Java program using a Java Development Environment like jdeveloper or JBuilder.
2.Load the Java program into Oracle8i using either the create or replace
Java source command, or with the loadjava utility.
3.Publish your Java procedure to SQL. This step identifies your Java
Procedure to SQL and PL/SQL by exposing the procedure entry point,
Mapping datatypes in Java to PL/SQL or SQL, and indicating
Parameter-passing between Java and PL/SQL or SQL.

(1) Write a Java program
--- You can directly create Java source files in SQL * Plus. Of course, if a compiled Java class exists, you can skip this step and release the Java program directly.
SQL> -- first, create the Java source code
SQL> Create or replace Java source named "hello"
Public class Hello {
Static Public String message (string name ){
Return "hello," + name;
}
}
/
Java created.
(2) Release Java programs
SQL> -- Now, publish it to SQL
SQL> Create or replace function Hello (name varchar2) return varchar2
As language Java name
'Hello. Message (Java. Lang. String) return java. Lang. string ';
Function created.
(3) Use the released Java program
SQL> -- now, you can use the Java procedure from a SQL statement
SQL> select Hello ('World! ') From dual;
Hello ('World! ')
---------------
Hello world!
--- The hello function does not support Chinese Characters in 8i and 9i. For example:
SQL> select Hello ('Hello! ') From dual;
Hello ('Hello! ')
------------------
Hello!

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.