Java Unlucky Exception: java.lang.NoSuchMethodError

I wrote an application, it worked fine for 3 years, but! Today, when they try to run this application, an unexpected exception has occurred:

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

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

Note that the only difference is the JRE (there used to be 1.6, and the new one was 1.7)

+7
source share
3 answers

Fixed!! And guess what! A copy of old jre (1.5.08) was built into the HP printer driver, and the address was added to the PATH !

0
source

Odd. It clearly references the isValid(int) method in java.sql.Connection

In your stacktrace, I also see me and 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 . Therefore, the method is definitely called. Note: the character to the right of parentheses indicates the type of method to return, and this method returns boolean (Z).

Here are the only ideas I can think of:

  • The source code you presented does not match what really works in your environment. (for example, maybe your patch has never been applied?)

  • In addition, Java 5 may work in your environment, since the isValid(int) method does not appear until Java 6.

+5
source

Sorry, I can not comment.

Have you just replaced jvm and none of your cool files? Try your sources in the IDE (don't forget to replace dependencies, etc. too), so that your sources are recompiled and learn about the new signatures that came with 1.7.

The rest I go with Julius Davis. Java should call isValid () (it would be interesting what would happen if you change it to the logical nameOtherThanAMethodOfConnection = false;).

+1
source

All Articles