我写了一个应用程序,它可以正常工作 3 年,但是!今天,当他们尝试运行此应用程序时,引发了意外的异常:
INFO | jvm 1 | 2013/04/17 10:02:40 | Exception in thread "Thread-1" java.lang.NoSuchMethodError: java.sql.Connection.isValid(I)Z
INFO | jvm 1 | 2013/04/17 10:02:40 | at lib.MySQLConnectionPatch.SearchInCache(MySQLConnectionPatch.java:103)
INFO | jvm 1 | 2013/04/17 10:02:40 | at lib.MySQLConnectionPatch.getConnection(MySQLConnectionPatch.java:79)
INFO | jvm 1 | 2013/04/17 10:02:40 | at lib.SQLManager.establishSqlConnection(SQLManager.java:62)
INFO | jvm 1 | 2013/04/17 10:02:40 | at lib.SQLManager.establishSqlConnection(SQLManager.java:30)
INFO | jvm 1 | 2013/04/17 10:02:40 | at lib.tasks.classes.sql.executeQuery.execute(executeQuery.java:49)
INFO | jvm 1 | 2013/04/17 10:02:40 | at Components.TTask.run(TTask.java:86)
INFO | jvm 1 | 2013/04/17 10:02:40 | at Components.ThreadTask.run(ThreadTask.java:29)
INFO | jvm 1 | 2013/04/17 10:02:40 | at lib.tasks.classes.fori.execute(fori.java:66)
INFO | jvm 1 | 2013/04/17 10:02:40 | at Components.TTask.run(TTask.java:86)
INFO | jvm 1 | 2013/04/17 10:02:40 | at Components.ThreadTask.run(ThreadTask.java:29)
INFO | jvm 1 | 2013/04/17 10:02:40 | at lib.tasks.classes.fori.execute(fori.java:66)
INFO | jvm 1 | 2013/04/17 10:02:40 | at Components.TTask.run(TTask.java:86)
INFO | jvm 1 | 2013/04/17 10:02:40 | at Components.ThreadTask.run(ThreadTask.java:29)
INFO | jvm 1 | 2013/04/17 10:02:40 | at Components.ThreadTask.run(ThreadTask.java:44)
INFO | jvm 1 | 2013/04/17 10:02:40 | at LauncherService.LaunchService.run(LaunchService.java:38)
MySQLConnectionPatch.java/SearchInCache的代码是
private Connection SearchInCache(String key) {
Connection result = null;
try{
if (!connections.isEmpty())
result = connections.get(key);
} catch (Exception ex){
}
if (result != null){
boolean isValid = false; /** THIS IS LINE 103 WHERE EXCEPTION RAISED **/
try {
Statement s = result.createStatement();
if (s.execute("SHOW STATUS;")){
isValid = true;
}
s.close();
} catch (Exception ex) {
isValid = false;
}
if (!isValid){
connections.remove(key);
messageLog.stdwar("MySQL_PATCH: ONE CONNECTION EXPIRED :: force close");
try {
result.close();
} catch (SQLException ex) {
messageLog.stderr("MySQL_PATCH: CLOSING CONNECTION ERROR: "+ex.getMessage());
}
result = null;
}
}
return result;
}
我想知道为什么要boolean isValid = false;
提出 Exception java.lang.NoSuchMethodError: java.sql.Connection.isValid(I)Z
。
请注意,唯一不同的是 JRE(以前是 1.6,新的是 1.7)