【发布时间】:2011-11-07 10:34:42
【问题描述】:
假设您有一个 Java 类,它定义了一个 copyFile(String, String) 方法:
public class FileSystem {
public static void copyFile(String sourcePath, String destinationPath)
throws IOException
{
// ignore the fact that I'm not properly managing resources...
FileInputStream source = new FileInputStream(sourcePath);
FileOutputStream destination = new FileOutputStream(destinationPath);
copyStream(source, destination);
source.close();
destination.close();
}
private static void copyStream(InputStream source, OutputStream destination)
throws IOException
{
byte[] buffer = new byte[1024];
int length;
while ( (length = source.read(buffer)) != -1 ) {
destination.write(buffer, 0, length);
}
}
}
假设您将其包装在 Java 存储过程中:
CREATE PROCEDURE copy_file (source_path VARCHAR2, destination_path VARCHAR2)
AS LANGUAGE JAVA
NAME 'FileSystem.copyFile(String, String)';
现在假设您调用 copy_file 存储过程并抛出 Java IOException:
BEGIN
copy_file( '/some/file/that/does/not/exist.txt', '/path/to/destination.txt' );
END;
在 PL/SQL 块中,引发的错误是:
ORA-29532 Java 调用被未捕获的 Java 异常终止
错误消息还包含未捕获的Exception 的描述,但它仍然是ORA-29532。有没有办法从 Java 中抛出一个 Exception 来指示错误代码和在 PL/SQL 中引发的错误消息?
【问题讨论】:
标签: java oracle stored-procedures plsql ora-29532