我想检测数据库何时关闭,并且我知道一旦数据库关闭它就会抛出 SQLException。使用Connection.isValid()。超时参数代表什么?它说:
timeout - - The time in seconds to wait for the database operation used to validate the connection to complete. If the timeout period expires before the operation completes, this method returns false. A value of 0 indicates a timeout is not applied to the database operation.
这是什么意思?
最佳答案
isValid() 方法允许您检查连接的有效性。
对于此方法,您可以指定一个以秒为单位的超时,当内部有效性检查完成之前超时,该方法将返回 false。
如果您不希望程序等待很长时间,以防有效性检查花费太长时间,这非常有用。
如果您将 0 作为超时输入,则不会应用超时,您的程序将等待检查完成。
关于java - 检测数据库已关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23562721/