【问题标题】:How to implement isValid connection for using with Oracle driver classes12?如何实现与 Oracle 驱动程序类一起使用的 isValid 连接12?
【发布时间】:2012-07-05 18:27:33
【问题描述】:

我需要实现

boolean isValid(int timeout) 

类似于 jdk6 中的 java.sql.Connection。但应该使用 Oracle 瘦驱动程序类 12。 很明显我可以运行小查询,但是超时呢?我应该为它创建单独的线程吗? 谢谢。

【问题讨论】:

  • 为什么不直接使用适用于 Java 6 的 Oracle JDBC 驱动程序?
  • 我无法选择。这不取决于我。如果可以的话——我从不问这个问题。
  • 我不明白你的意思。为什么你不能使用它?想着可以修改 Java 1.2 Oracle JDBC 驱动程序以便在 Java 6 下使用它是愚蠢的,因为您可以获取 Java 6 驱动程序。
  • 我也对这个问题感兴趣。

标签: java oracle jdbc connection


【解决方案1】:

对于 OJDB7:

isValid(int timeout) - 是方法 pingDatabase(int i)
pingDatabase() 的包装 - 进行查询“SELECT 'x' FROM DUAL "。
pingDatabase(int i) - 在单独的线程中进行相同的查询。

答案 - 是的,您必须在单独的线程中提出一个小请求。

try {
    Thread thread = new Thread(new Runnable() {
        public void run() {
            try {
                result = ...make query and verify result
            } catch(Throwable throwable) {
                return false;
            }
        }
    });
    thread.start();
    thread.join(timeout);
    return result;
catch(InterruptedException interruptedexception) {
    return false;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-12
    • 2012-04-04
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    相关资源
    最近更新 更多