在 sql Developer 中运行以下代码时出现以下错误:
创建java源代码-
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED demoskr1 AS
package ScreenShot;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.*;
class demoskr1
{
public static void main(String args[]) throws Exception
{
try{
Thread.sleep(5000);
Robot awt_robot = new Robot();
String path = "C:\\Users\\pbafna\\workspace\\shot.jpg";
BufferedImage Entire_Screen = awt_robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
ImageIO.write(Entire_Screen, "jpg", new File(path));
System.out.println("Screenshot saved");
}
catch (Exception e) {
System.out.println("Something went wrong.");
}
}
};
创建过程-
create or replace procedure proc_capture
as
language Java
name 'demoskr1.main(java.lang.String[])';
运行程序-
begin
proc_capture();
end;
运行后我收到以下错误:
ORA-29532: Java call terminated by uncaught Java exception: java.lang.NoClassDefFoundError
ORA-06512: at "XXOSC.PROC_CAPTURE", line 1
ORA-06512: at line 2
29532. 00000 - "Java call terminated by uncaught Java exception: %s"
*Cause: A Java exception or error was signaled and could not be
resolved by the Java code.
*Action: Modify Java code, if this behavior is not intended.
最佳答案
您正在使用java.awt.Robot
它需要图形、非 headless 环境才能正常工作,而数据库服务器不提供它。根据User Interfaces on the Server Oracle 文档:
Oracle Database furnishes all core Java class libraries on the server, including those associated with presentation of the user interfaces. However, it is inappropriate for code running on the server to attempt to materialize or display a user interface on the server. Users running applications in Oracle JVM environment should not be expected nor allowed to interact with or depend on the display and input hardware of the server where Oracle Database is running.
关于java - ORA-29532 : Java call terminated by uncaught Java exception: java. lang.NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54925564/