MySQL Forums
Forum List  »  Connector/JDBC and Java

JDBC hanging upon connection
Posted by: James Coster
Date: May 21, 2012 08:22AM

I'm running connector 5.1.20 on Ubuntu 11.10.

~# java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

I have the following code in a jar file:
Connection conn = null;
System.out.println("Init JDBC driver...");
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
System.out.println("Getting connection from DriverManager...");
conn = DriverManager.getConnection("jdbc:mysql://<DB>?user=<USER>&password=<MYPASSWORD>");
System.out.println("DB connection opened successfully!");

catch (Exception ex)

20% of the time, the above code works fine, as expected; a connection is established, no errors. However, the other 80% of the time the code hangs on "Getting connection from DriverManager...". No exceptions, nothing, even for 20+ minutes. I can't ctrl + c out; the thread has hung.

jstack output:
"main" prio=10 tid=0x0000000041b3c800 nid=0x17fc runnable [0x00007feb60ca5000]
java.lang.Thread.State: RUNNABLE
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(
at java.lang.ClassLoader.defineClass(
at Method)
at java.lang.ClassLoader.loadClass(
- locked <0x00000000f3230390> (a sun.misc.Launcher$AppClassLoader)
at sun.misc.Launcher$AppClassLoader.loadClass(
- locked <0x00000000f3230390> (a sun.misc.Launcher$AppClassLoader)
at java.lang.ClassLoader.loadClass(
at com.mysql.jdbc.NonRegisteringDriver.connect(
at java.sql.DriverManager.getConnection(
at java.sql.DriverManager.getConnection(
at DBTest.<init>(
at DBTest.main(

Someone has suggested it could be to not releasing connections, but it can happen the first time after reboot so it can't be that...

Has anyone got advice? The above code is a standalone jar I've created to try to troubleshoot this issue, there's nothing else going on.

Any help greatly appreciated...

Options: ReplyQuote

Written By
JDBC hanging upon connection
May 21, 2012 08:22AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.