一:例子
1,创建JAVA CLASS
a)对于简单的CLASS,我们可以直接在PLSQL里定议,如下
create or replace and compile java source named "HelloWorld"
as
package com.test;
public class HelloWorld {
public static String sayHello(String name){
System.out.println("hello::"+ name);
return "hello::"+ name;
}
}
或者
package com.test;
public class HelloWorld {
public static String sayHello(String name){
System.out.println("hello::"+ name);
return "hello==="+ name;
}
}
注意由于jdk版本不一致而引起的错误:
$ORACLE_HOME/jdk/javac HelloWorld.java
Uncaught exception System error: java/lang/UnsupportedClassVersionError
loadjava -user rudy/jume123456 HelloWorld.class
2)创建对就的SQL FUNCTION如:
create or replace function HelloWorld(p_name in varchar2)
return varchar2
as
language java name 'com.test.HelloWorld.sayHello(java.lang.String) return java.lang.String';
3)通过select HelloWorld('java') from dual;
二:例子
create or replace and compile java source named "javademo1" as
import java.sql.*;
public class JavaDemo1 {
public static void main(String[] args) {
System.out.println("hello, javademo1");
}
}
create or replace procedure javademo1
as
language java name 'JavaDemo1.main(java.lang.String[])';
set serveroutput on size 5000
call dbms_java.set_output(5000);
execute javademo1;
三:例子
public class hello
{
public static void msg(String name)
{
System.out.println("hello,"+name);
}
};
$ORACLE_HOME/jdk/bin/javac hello.java
create or replace directory CLASS_DIR as '/u01/app/java/com/test';
create or replace java class using bfile(class_dir,'hello.class');
create or replace procedure prc_hello(p_name VARCHAR2)
as
language java name 'hello.msg(java.lang.String)';
call prc_hello('java');
exec dbms_java.set_output(2000);
四:例子
public class hello
{
public static void main(String[] args)
{
System.out.println("Hello");
hello h = new hello();
h.insertM(9);
}
public static void insertM(int pid)
{
System.out.println("This is the method insertM.");
}
}
loadjava -u rudy/jume123456 -v -resolve hello.java
create procedure prc_hehe as language java name 'hello.main(java.lang.String[])';
call prc_hehe();
set serveroutput on size 2000
exec dbms_java.set_output(2000);
1,创建JAVA CLASS
a)对于简单的CLASS,我们可以直接在PLSQL里定议,如下
create or replace and compile java source named "HelloWorld"
as
package com.test;
public class HelloWorld {
public static String sayHello(String name){
System.out.println("hello::"+ name);
return "hello::"+ name;
}
}
或者
package com.test;
public class HelloWorld {
public static String sayHello(String name){
System.out.println("hello::"+ name);
return "hello==="+ name;
}
}
注意由于jdk版本不一致而引起的错误:
$ORACLE_HOME/jdk/javac HelloWorld.java
Uncaught exception System error: java/lang/UnsupportedClassVersionError
loadjava -user rudy/jume123456 HelloWorld.class
2)创建对就的SQL FUNCTION如:
create or replace function HelloWorld(p_name in varchar2)
return varchar2
as
language java name 'com.test.HelloWorld.sayHello(java.lang.String) return java.lang.String';
3)通过select HelloWorld('java') from dual;
二:例子
create or replace and compile java source named "javademo1" as
import java.sql.*;
public class JavaDemo1 {
public static void main(String[] args) {
System.out.println("hello, javademo1");
}
}
create or replace procedure javademo1
as
language java name 'JavaDemo1.main(java.lang.String[])';
set serveroutput on size 5000
call dbms_java.set_output(5000);
execute javademo1;
三:例子
public class hello
{
public static void msg(String name)
{
System.out.println("hello,"+name);
}
};
$ORACLE_HOME/jdk/bin/javac hello.java
create or replace directory CLASS_DIR as '/u01/app/java/com/test';
create or replace java class using bfile(class_dir,'hello.class');
create or replace procedure prc_hello(p_name VARCHAR2)
as
language java name 'hello.msg(java.lang.String)';
call prc_hello('java');
exec dbms_java.set_output(2000);
四:例子
public class hello
{
public static void main(String[] args)
{
System.out.println("Hello");
hello h = new hello();
h.insertM(9);
}
public static void insertM(int pid)
{
System.out.println("This is the method insertM.");
}
}
loadjava -u rudy/jume123456 -v -resolve hello.java
create procedure prc_hehe as language java name 'hello.main(java.lang.String[])';
call prc_hehe();
set serveroutput on size 2000
exec dbms_java.set_output(2000);