Wednesday, July 25, 2012
MySQL jdbc driver hangs only with jnlp...
There is a strange bug with the MySQL jdbc driver that happens only when the application is launched through JavaWebStart. This issue caused me a lot of head scratching until the solution surfaced, somehow by luck. This post is just to share the information in case somebody has the same problem.
Normally, the following code connects to the server:
Class.forName("com.mysql.jdbc.Driver").newInstance();
Properties info = new Properties();
info.setProperty("user", username);
info.setProperty("password", password);
info.setProperty("timeout", "1");
connection = DriverManager.getConnection( "serverName", info );
This code works both when running directly in Eclipse and also when starting the application from a compiled jar.
If the network connection is ok, then it connects, and if not, then it will give either a timeout exception or an unknown host exception or something similar.
Weirdly, when the same compiled jar is launched using a jnlp file over JavaWebStart, then the application just hung. It would sit for hours and hours, not giving any timeout or exception or anything. Looking in the Java console gave no clues, but narrowed the problem down to the line:
connection = DriverManager.getConnection( "serverName", info );
The problem was diagnosed many many months later as a host resolution issue. When the "serverName" was replaced with "serverName.company.com" then the application connected properly.
So, just in case you have the same problem but only when using JavaWebStart, I would recommend adding the domain suffix to the server address and giving that a try.
Hope it helps!
Labels:
MySQL
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment