设置网络超时 [英] Setting Network Timeout

查看:148
本文介绍了设置网络超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Java设置网络超时我的Oracle数据库连接。但是,我收到了一个错误。下面是示例代码,它是相应的例外。

I'm trying to set a network time-out my Oracle database Connection in Java. However, I'm getting an error. Below is sample code and it's respective exception.

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);
}



我得到的例外是:


The Exception I'm getting is:

Exception in thread "main" java.lang.AbstractMethodError: oracle.jdbc.driver.T4CConnection.setNetworkTimeout(Ljava/util/concurrent/Executor;I)V
    at ke.co.smart.Switch.<init>(Switch.java:524)
    at ke.co.smart.Switch.main(Switch.java:161)
Java Result: 1



我认为它与抽象方法有关(读取AbstractMethodError)。什么可能导致这个错误,因为我只实现了我认为已经在Java中定义的方法,因此,不拒绝编译。



N.B.如果有抽象方法,Java不允许编译具体类。


I believe it has to do with a method being abstract (read AbstractMethodError). What could probably cause this error as I have only implemented the method which I think is already defined within Java, and thus, does not refuse to compile.

N.B. Java does not allow compilation of concrete classes if there are abstract methods.

推荐答案

http://stackoverflow.com/questions/10654547/how-to-use-java-sql-connection-setnetworktimeout [ ^ ]。


在对上述主题做了一些研究,并检查了Java API的Oracle实现之后,oracles JDBC 4.0还没有实现方法 setNetworkTimeout 。这会导致错误 java.lang.AbstractMethodError 。我认为,由于未能实现 Connection接口 的所有方法,有一些API违规导致JVM抛出指示的错误。
After doing some more research on the above topic, and checking the Oracle implementation of the Java API, oracles JDBC 4.0 has not implemented the method setNetworkTimeout. That causes the error java.lang.AbstractMethodError. I think that by failing to implement all methods of the Connection interface, there are some API violations that causes the JVM to throw the indicated error.


这篇关于设置网络超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆