title: Android mysql-connector-java Library
body: <p>I'm trying to make a connection between my android application and a Mysql Server.</p>
  
  <p>I got two applications and exactly the same code. One application does the connection perfectly but the other get a Comunications link failure.</p>
  
  <p>This code is in the onCreate Method:</p>
  
  <pre><code>    Log.d("Trying to instantiate driver", "try");
      try {
                      Class.forName("com.mysql.jdbc.Driver").newInstance();
                      this.setTitle("Driver instantiated");
  
                      try {
                          conexionMySQL = DriverManager.getConnection("jdbc:mysql://"+ip+":"+port,user,pass);
                          Log.d("CONNECTION", "connected");
                      } catch (SQLException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                          Log.d("CONNECTION", "not connected: "+e.getMessage());
                      }
  
  
              } catch (ClassNotFoundException e) {
                      // TODO Auto-generated catch block
                  Log.d("com.mysql.jdbc.Driver", "NOT found");
                      this.setTitle(".....Class com.mysql.jdbc.Driver not found!");
                      e.printStackTrace();
              } catch (IllegalAccessException e) {
                  Log.d("com.mysql.jdbc.Driver", "ilegal access");
                      this.setTitle("Illegal access");
                      // TODO Auto-generated catch block
                      e.printStackTrace();
              } catch (InstantiationException e) {
                  Log.d("com.mysql.jdbc.Driver", "Instantiation exception");
                      this.setTitle("instantiation exc eption");
                      // TODO Auto-generated catch block
                      e.printStackTrace();
              }
  </code></pre>
  
  <p>On the working application I got the following Log:</p>
  
  <pre><code>05-31 19:17:47.105: D/Trying to instantiate driver(17103): try
  05-31 19:17:53.635: D/CONNECTION(17103): connected
  </code></pre>
  
  <p>On the application that is not working I got the following log:</p>
  
  <pre><code>05-31 19:21:43.395: D/Trying to instantiate driver(18088): try
  05-31 19:21:43.795: W/dalvikvm(18088): VFY: unable to find class referenced in signature (Ljavax/naming/Reference;)
  05-31 19:21:43.795: I/dalvikvm(18088): Could not find method javax.naming.Reference.get, referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.initializeFrom
  05-31 19:21:43.795: W/dalvikvm(18088): VFY: unable to resolve virtual method 16799: Ljavax/naming/Reference;.get (Ljava/lang/String;)Ljavax/naming/RefAddr;
  05-31 19:21:43.795: D/dalvikvm(18088): VFY: replacing opcode 0x6e at 0x0004
  05-31 19:21:43.795: W/dalvikvm(18088): VFY: unable to find class referenced in signature (Ljavax/naming/Reference;)
  05-31 19:21:43.795: E/dalvikvm(18088): Could not find class 'javax.naming.StringRefAddr', referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.storeTo
  05-31 19:21:43.795: W/dalvikvm(18088): VFY: unable to resolve new-instance 1537 (Ljavax/naming/StringRefAddr;) in Lcom/mysql/jdbc/ConnectionPropertiesImpl$ConnectionProperty;
  05-31 19:21:43.795: D/dalvikvm(18088): VFY: replacing opcode 0x22 at 0x0006
  05-31 19:21:43.795: D/dalvikvm(18088): DexOpt: unable to opt direct call 0x41a1 at 0x14 in Lcom/mysql/jdbc/ConnectionPropertiesImpl$ConnectionProperty;.storeTo
  05-31 19:21:43.835: I/dalvikvm(18088): Could not find method java.lang.management.ManagementFactory.getThreadMXBean, referenced from method com.mysql.jdbc.MysqlIO.appendDeadlockStatusInformation
  05-31 19:21:43.835: W/dalvikvm(18088): VFY: unable to resolve static method 16114: Ljava/lang/management/ManagementFactory;.getThreadMXBean ()Ljava/lang/management/ThreadMXBean;
  05-31 19:21:43.835: D/dalvikvm(18088): VFY: replacing opcode 0x71 at 0x0079
  05-31 19:21:43.895: W/System.err(18088): com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
  05-31 19:21:43.895: W/System.err(18088): The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  05-31 19:21:43.895: W/System.err(18088):    at java.lang.reflect.Constructor.constructNative(Native Method)
  05-31 19:21:43.895: W/System.err(18088):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1121)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.MysqlIO.&lt;init&gt;(MysqlIO.java:355)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2479)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.ConnectionImpl.&lt;init&gt;(ConnectionImpl.java:834)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.JDBC4Connection.&lt;init&gt;(JDBC4Connection.java:47)
  05-31 19:21:43.895: W/System.err(18088):    at java.lang.reflect.Constructor.constructNative(Native Method)
  05-31 19:21:43.895: W/System.err(18088):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
  05-31 19:21:43.895: W/System.err(18088):    at java.sql.DriverManager.getConnection(DriverManager.java:175)
  05-31 19:21:43.895: W/System.err(18088):    at java.sql.DriverManager.getConnection(DriverManager.java:209)
  05-31 19:21:43.895: W/System.err(18088):    at com.unilocation.unilocation.MainActivity.onCreate(MainActivity.java:169)
  05-31 19:21:43.895: W/System.err(18088):    at android.app.Activity.performCreate(Activity.java:5191)
  05-31 19:21:43.895: W/System.err(18088):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
  05-31 19:21:43.895: W/System.err(18088):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2037)
  05-31 19:21:43.895: W/System.err(18088):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2098)
  05-31 19:21:43.895: W/System.err(18088):    at android.app.ActivityThread.access$600(ActivityThread.java:138)
  05-31 19:21:43.895: W/System.err(18088):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1204)
  05-31 19:21:43.895: W/System.err(18088):    at android.os.Handler.dispatchMessage(Handler.java:99)
  05-31 19:21:43.895: W/System.err(18088):    at android.os.Looper.loop(Looper.java:137)
  05-31 19:21:43.895: W/System.err(18088):    at android.app.ActivityThread.main(ActivityThread.java:4872)
  05-31 19:21:43.895: W/System.err(18088):    at java.lang.reflect.Method.invokeNative(Native Method)
  05-31 19:21:43.895: W/System.err(18088):    at java.lang.reflect.Method.invoke(Method.java:511)
  05-31 19:21:43.895: W/System.err(18088):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
  05-31 19:21:43.895: W/System.err(18088):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
  05-31 19:21:43.895: W/System.err(18088):    at dalvik.system.NativeStart.main(Native Method)
  05-31 19:21:43.895: W/System.err(18088): Caused by: java.net.SocketException: android.os.NetworkOnMainThreadException
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.StandardSocketFactory.unwrapExceptionToProperClassAndThrowIt(StandardSocketFactory.java:410)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:271)
  05-31 19:21:43.895: W/System.err(18088):    at com.mysql.jdbc.MysqlIO.&lt;init&gt;(MysqlIO.java:305)
  05-31 19:21:43.895: W/System.err(18088):    ... 27 more
  05-31 19:21:43.895: D/CONNECTION(18088): not connected: Communications link failure
  05-31 19:21:43.895: D/CONNECTION(18088): The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
  </code></pre>
  
  <p>The mysql-connector-java-5.1.24-bin on the working library is shown correctly:</p>
  
  <p><a href="https://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-xaf1/t1.0-9/10173658_283023051875514_2502503371478517760_n.jpg" rel="nofollow">image1</a></p>
  
  <p>But the mysql-connector-java-5.1.24-bin on the not working library has got an small icon:</p>
  
  <p><a href="https://scontent-a-mad.xx.fbcdn.net/hphotos-xpf1/t1.0-9/10371982_283023018542184_9001707904284160295_n.jpg" rel="nofollow">image2</a></p>
  
  <p>What is the problem with the library?</p>