Question

I wrote an application, an it was working fine for 3 years, but! today when they try to run this application, an unexpected exception raised:

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)

code of MySQLConnectionPatch.java/SearchInCache is

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

I wonder why boolean isValid = false; raise Exception java.lang.NoSuchMethodError: java.sql.Connection.isValid(I)Z.

Note that the only thing differs is JRE (former was 1.6, and the new is 1.7)

Était-ce utile?

La solution 3

Fixed!! And guess what! A copy of old jre (1.5.08) was embeded in HP Printer driver and the address was added to the PATH environment variable!

Autres conseils

Odd. It's clearly referencing the isValid(int) method in java.sql.Connection

In your stacktrace I also see an I and a Z: java.sql.Connection.isValid(I)Z

Those correspond to int (I) and boolean (Z), the exact signature for the method in java.sql.Conneciton. So a method is definitely being called. Note: the character to the right of the parentheses indicates the method's return type, and this method returns boolean (Z).

Here are the only ideas I can think of:

  1. The source code you presented does not correspond to what's actually running in your environment. (e.g., maybe your "patch" is never really applied?)

  2. Also, your environment might be running Java 5, since the isValid(int) method does not show up until Java 6.

Sorry, I can't comment.

Did you just replace the jvm and none of your class-files? Please try your sources in an IDE (remember to replace also dependencies etc), so that you sources are recompiled and know about the new signatures that came with 1.7.

For the rest, I go with Julius Davies. Java should call isValid() (would be interesting, what happens, if you change it to boolean nameOtherThanAMethodOfConnection = false;).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top