自Oracle 9以来我们一直在使用的一小段Java代码在Oracle 12.2中出现编译错误。
(看起来代码来自这里:https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:439619916584)
12.2中有什么变化,所以我们需要更改我们的Java代码或需要授予的一些新权限吗?
编辑:使用SQL插入代码注释掉该行会导致正确的编译。也许这种语法不再可用?
create or replace and compile java source named "DirList"
as
import java.io.*;
import java.sql.*;
import java.text.SimpleDateFormat;
public class ChpDirList{
public static void getList(String directory)
throws SQLException {
File path = new File( directory );
String[] list = path.list();
String element;
for(int i = 0; i < list.length; i++){
element = list[i];
String fpath=directory+"/"+list[i];
File f = new File(fpath);
long len;
String ftype;
if (f.isFile()) {
len = f.length();
ftype = "F";
} else {
len = 0;
ftype = "D";
}
#sql { INSERT INTO NGM_DIR_LIST (file_name, file_length, file_type, file_modified)
VALUES (:element, :len, :ftype, null) };
}
}
}
/
错误消息:
Compilation errors for JAVA SOURCE NGM42.DIRLIST
#13#10Error: An exception has occurred in the compiler (1.8.0_121-ea). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
Line: 0
#13#10Error: java.lang.IllegalArgumentException
Line: 0
#13#10Error: at com.sun.tools.javac.util.JCDiagnostic.<init>(JCDiagnostic.java:412)
Line: 0
#13#10Error: at com.sun.tools.javac.util.JCDiagnostic$Factory.create(JCDiagnostic.java:238)
Line: 0
#13#10Error: at com.sun.tools.javac.util.JCDiagnostic$Factory.error(JCDiagnostic.java:103)
Line: 0
#13#10Error: at com.sun.tools.javac.util.AbstractLog.error(AbstractLog.java:117)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavaTokenizer.lexError(JavaTokenizer.java:136)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavaTokenizer.readToken(JavaTokenizer.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.Scanner.nextToken(Scanner.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.nextToken(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.accept(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.block(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.block(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.parseStatement(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.blockStatement(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.parseStatementAsBlock(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.parseStatement(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.blockStatement(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.blockStatements(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.block(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.block(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.parseStatement(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.blockStatement(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.parseStatementAsBlock(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.parseStatement(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.blockStatement(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.blockStatements(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.block(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.block(JavacParser.java)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.methodDeclaratorRest(JavacParser.java:3586)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.classOrInterfaceBodyDeclaration(JavacParser.java:3532)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.classOrInterfaceBody(JavacParser.java:3436)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.classDeclaration(JavacParser.java:3285)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.classOrInterfaceOrEnumDeclaration(JavacParser.java:3226)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.typeDeclaration(JavacParser.java:3215)
Line: 0
#13#10Error: at com.sun.tools.javac.parser.JavacParser.parseCompilationUnit(JavacParser.java:3155)
Line: 0
#13#10Error: at com.sun.tools.javac.main.JavaCompiler.parse(JavaCompiler.java:676)
Line: 0
#13#10Error: at com.sun.tools.javac.main.JavaCompiler.parseFiles(JavaCompiler.java:1037)
Line: 0
#13#10Error: at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:926)
Line: 0
#13#10Error: at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:890)
Line: 0
#13#10Error: at oracle.aurora.jdkcompiler.JdkDriver.compile(JdkDriver.java:572)
Line: 0
#13#10Error: at oracle.aurora.rdbms.Compiler.doCompile(Compiler.java:663)
Line: 0
#13#10Error: at oracle.aurora.rdbms.Compiler.access$000(Compiler.java:57)
Line: 0
#13#10Error: at oracle.aurora.rdbms.Compiler$1.run(Compiler.java:319)
Line: 0
#13#10Error: at java.security.AccessController.doPrivileged(Native Method)
Line: 0
#13#10Error: at oracle.aurora.rdbms.Compiler.compile(Compiler.java:317)
Line: 0
答案 0 :(得分:3)
事实证明,Oracle 12.2不再支持服务器端SQLJ。稍微改写一下代码就可以了。
create or replace and compile java source named "DirList" as
import java.io.*;
import java.sql.*;
public class ChpDirList {
public static void getList(String directory)
throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:default:connection:");
String sql = "INSERT INTO NGM_DIR_LIST (file_name, file_length, file_type) values (?,?,?)";
File path = new File(directory);
String[] list = path.list();
String element;
for (int i = 0; i < list.length; i++) {
element = list[i];
String fpath = directory + "/" + list[i];
File f = new File(fpath);
long len;
String ftype;
if (f.isFile()) {
len = f.length();
ftype = "F";
} else {
len = 0;
ftype = "D";
}
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, element);
pstmt.setLong(2, len);
pstmt.setString(3, ftype);
pstmt.executeUpdate();
pstmt.close();
}
}
}