我正在尝试使用Java设置网络超时我的Oracle数据库连接。但是,我遇到了错误。以下是示例代码及其各自的例外。
try{
conn = new Database("oracle").connect();
conn.setNetworkTimeout(null, 30000); //I don't have an Executor, so the field is set to null
System.out.println(Switch.date() + " -> Database Connection Initialized");
}
catch(SQLException ex){
Logger.getLogger(Switch.class.getName()).log(Level.SEVERE, null, ex);
}
我得到的异常是:
Exception in thread "main" java.lang.AbstractMethodError:oracle.jdbc.driver.T4CConnection.setNetworkTimeout(Ljava/util/concurrent/Executor;I)V
at ke.co.smart.Switch.(Switch.java:524)
at ke.co.smart.Switch.main(Switch.java:161)
Java Result: 1
我相信这与抽象方法有关(请参见AbstractMethodError)。可能导致此错误的原因是我只实现了我认为已经在Java中定义的方法,因此不拒绝编译。
注意:如果有抽象方法,Java不允许编译具体的类。