Oracle triggers reverse call to Java program

Source: Internet
Author: User

Import jar Package in Oracle to import the required jar package, we put the edited Java class into a jar package, directly in the oarcle to write a simple call on it,1, the operating system needs to have a JDK that supports the Loadjava command. 2, load the Jlha.jar package into the Oracle database. Operation process: In DOS environment, input command: Loadjava-r-f-o-user usscares/[email protected] Jlha.jar Note: The jar package is to be compiled in 1.4 environment, Project right-click Properties Java compiler Compoler compliance level1.4 or Else version 49similar error calling Java class Oracle calls the Java class method mainly has the following three kinds: load with the Loadjava method, may be debugging convenient, it is said that this method is more common. C:\test\hello.java Public classhello{ Public Static voidMain (string[] args) {System.out.println ("Hello"); Hello h=Newhello (); H.insertm (9); }     Public Static voidInsertm (intpid) {System.out.println ("This is the method Insertm."); }} C:\test>loadjava-u Test/[email Protected]-V-Resolve Hello.javasql> CREATE PROCEDURE prc_hehe as language Java name ' Hello.main (java.lang.string[])The process has been created. SQL>call Prc_hehe (); calls complete. SQL> Set serveroutput on Size 2000SQL>call Prc_hehe (); calls complete. SQL> Exec dbms_java.set_output (2000);P L/The SQL process has completed successfully. SQL>Call Prc_hehe (); Hellothis is the method Insertm. Call complete. SQL>show errors; modify Java class, first remove Reload, method: Dropjava-u test/[email protected]-V-Resolve Hello.javaloadjava-u test/[email protected]-V-Resolve Hello.java Creating a Create or Replace with SQL statement and compile Java source named Heheas Public classhello{ Public Static voidmsg (String name) {System.out.println ("Hello," +name); }}; Create or Replace procedure Prc_hehe (p_name VARCHAR2) aslanguage Java name' Hello.msg (java.lang.String) ';--Call Result SQL> Call Prc_hehe (' Oopp '); Hello,oopp use an external CLASS file to mount the Create or replace directory Class_dir as' C:\Test '; Create or replace JavaclassUsing bfile (Class_dir, ' Hello.class 'Create or Replace procedure Prc_hello (p_name VARCHAR2) aslanguage Java name' Hello.msg (java.lang.String) ';--test Result SQL> Call Prc_hello (' Java '); Java may appear error SQL> Call Prc_hello (' Jerry '); Call Prc_hello (' Jerry ')     *Section1line error: ORA-29516:aurora Assertion Failure: Assertion failure at eox.c:359uncaught exception System Error:java/lang/unsupportedclassversionerror Reason: The machine has multiple Java versions, and the Java version of Oracle is lower than the version set by the environment variable. Workaround: Use $oracle_home/jdk/Javac recompile java file Check Java has imported database select* from User_source where type like ' java% ' and NAME = ' <java file> 'Establish functioncreate OR REPLACE FUNCTION<FUNCTION_NAME> (<parameter LIST in ORACLE datatype>) return <oracle DATATYPE of return variable>As LANGUAGE JAVA NAME' <clase.method> (<parameter list in Java datatype>) return Java datatype of return variable 'Login to a user and create a Java program resource in PL/Java code in SQL is displayed in Java source that you write; Create or replace and compile Java source named BB_WX_REPLOSSSBK asImportJava.sql.*;ImportOracle.jdbc.driver.*; Public classbb_wx_replosssbk{/*** Loss of Social Security card*/     Public Staticstring Callproc (String Ssfzh, String spwd, String stype) {Oracledriver driver=NewOracledriver (); Connection Connection=NULL; CallableStatement cstmt=NULL; String Srtn= "Beg"; Try{Srtn= "Try Beg"; Connection= Drivermanager.getconnection ("Jdbc:oracle:thin:user/[email PROTECTED]:1521:ORCL"); Srtn= "Con"; Cstmt= Connection.preparecall ("{Call RUN_REPLOSSSBK (?,?,?,?)}"); Srtn= "Invoke"; Cstmt.setstring (1, Ssfzh); Cstmt.setstring (2, SPWD); Cstmt.setstring (3, stype); Cstmt.registeroutparameter (4, Java.sql.Types.VARCHAR); Srtn= "Set Value";            Cstmt.executeupdate (); Srtn= "Execute"; Srtn= Cstmt.getstring (4); }        Catch(Exception e) {Srtn=e.tostring ();        E.printstacktrace (); }        finally        {            Try            {                if(Cstmt! =NULL) {cstmt.close (); }                if(Connection! =NULL) {connection.close (); }            }            Catch(Exception e) {e.printstacktrace (); }        }        returnSrtn; }} Create a function that calls Java resources Create or Replace function RUN_BB_WX_REPLOSSSBK (Ssfz in Varchar2,spwd in Varchar2,stype in varchar2)returnvarchar2as language Java name' Bb_wx_replosssbk.callproc (java.lang.string,java.lang.string,java.lang.string) return java.lang.String 'Create a procedure call stored procedure Create or Replace procedure RUN (Ssfz in Varchar2,spwd in Varchar2,stype in Varchar2srtn out varchar2) Asbeg Inch--SRTN: =RUN_BB_WX_REPLOSSSBK (Ssfz in Varchar2,spwd in Varchar2,stype in varchar2); Select RUN_BB_WX_REPLOSSSBK (Ssfz in Varchar2,spwd, Varchar2,stype in varchar2) to Srtn from Dual;end;/attached: If Java Access file is required, use DBA user to empower exec dbms_java.grant_permission (' onboarding ', ' SYS:java.lang.RuntimePermission ', ' writefiledescriptor ', '); EXEC Dbms_java.grant_permission (' onboarding ', ' SYS:java.lang.RuntimePermission ', ' readfiledescriptor ', '); EXEC Dbms_java.grant_permission (' onboarding ', ' SYS:java.io.FilePermission ', ' <<all files>> ', ' execute '); The following statement of permission is exec dbms_java.revoke_permission (' onboarding ', ' SYS:java.lang.RuntimePermission ', ' writefiledescriptor ', '); EXEC Dbms_java.revoke_permission (' onboarding ', ' SYS:java.lang.RuntimePermission ', ' readfiledescriptor ', '); EXEC Dbms_java.revoke_permission (' onboarding ', ' SYS:java.io.FilePermission ', ' <<all files>> ', ' execute ');

Oracle triggers reverse calling Java programs

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.