在网上找到资料,模仿人家的步骤,先定义了一个Main.java文件,将程序参数写入一个已有文件中
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;/**
 *
 * @author  
 */
public class Main {  /**
  * @param args the command line arguments
  */
  public static void main(String args) {
  // TODO code application logic here
    
  String datas = "/home/oracle/test.txt";
  File data = new File(datas);
  try {
  StringBuffer content = new StringBuffer();
  content.append("Hello");
  content.append(args);
  FileWriter writer = new FileWriter(data,true);
  writer.write(content.toString());
  writer.flush();  } catch (FileNotFoundException e) {
  e.printStackTrace();
  } catch (IOException e) {
  e.printStackTrace();
  }  }}然后使用loadjva -user user/pass@test -o -v -f -r /home/oracle/Main.java
提示导入JAVA程序成功然后在sqlplus里创建一个存储过程
create or replace procedur file_test(name varchar2) as language java name 'Main.main(java.lang.String)';
/这个时候出现 Warning:procedure created with compilation errors.执行 show errors procedure file_test;
得到
0/0 PL/SQL:Compilation unit analysis terminated
1/55 PLS-00311:the declaration of "Main.main(java.lang.String)" is incomplete or malformed不知道原因在什么地方啊

解决方案 »

  1.   

    1. public static void main(String args[]) {2. create or replace procedure file_test(name varchar2) as language java name 'Main.main(java.lang.String[])';
      

  2.   

    你这个应用有两个问题:
    第1个问题:
    你的java实现函数不应该叫static void main(...),它与可执行函数体冲突,这是出错的原因。
    将其改名为main2吧。第2个问题,你的实现函数访问到外部文件,需要授权。看如下测试,全部通过:
    $ loadjava -user scott/tiger -v -resolve Main.java
    arguments: '-user' 'scott/tiger' '-v' '-resolve' 'Main.java'
    identical: Main
    skipping : source Main
    Classes Loaded: 0
    Resources Loaded: 0
    Sources Loaded: 0
    Published Interfaces: 0
    Classes generated: 0
    Classes skipped: 1
    Synonyms Created: 0
    Errors: 0
    SQL> conn system/*****SQL> call dbms_java.grant_permission( 'SCOTT', 'SYS:java.io.FilePermission', '/home/oracle/test.txt', 'write' ) ;Call completed.SQL> conn scott/****
    Connected.SQL> call file_test(' iihero');Call completed.
      

  3.   

    这是另外一种形式。create or replace and compile java source
    这样做的话,procedure中的参数name就传不进来了。