Problem in database connection class

Asked

Viewed 898 times

1

I’m having problems with my Mysql database connection class in Android Studio.

Error:

    10-16 15:04:02.872      532-532/com.example.dev.mbstore W/dalvikvm﹕ VFY: unable to find class referenced in signature (Ljavax/naming/Reference;)
10-16 15:04:02.872      532-532/com.example.dev.mbstore I/dalvikvm﹕ Could not find method javax.naming.Reference.get, referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.initializeFrom
10-16 15:04:02.872      532-532/com.example.dev.mbstore W/dalvikvm﹕ VFY: unable to resolve virtual method 8068: Ljavax/naming/Reference;.get (Ljava/lang/String;)Ljavax/naming/RefAddr;
10-16 15:04:02.872      532-532/com.example.dev.mbstore D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0004
10-16 15:04:02.882      532-532/com.example.dev.mbstore W/dalvikvm﹕ VFY: unable to find class referenced in signature (Ljavax/naming/Reference;)
10-16 15:04:02.882      532-532/com.example.dev.mbstore E/dalvikvm﹕ Could not find class 'javax.naming.StringRefAddr', referenced from method com.mysql.jdbc.ConnectionPropertiesImpl$ConnectionProperty.storeTo
10-16 15:04:02.882      532-532/com.example.dev.mbstore W/dalvikvm﹕ VFY: unable to resolve new-instance 518 (Ljavax/naming/StringRefAddr;) in Lcom/mysql/jdbc/ConnectionPropertiesImpl$ConnectionProperty;
10-16 15:04:02.882      532-532/com.example.dev.mbstore D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x0006
10-16 15:04:02.882      532-532/com.example.dev.mbstore D/dalvikvm﹕ DexOpt: unable to opt direct call 0x1f86 at 0x14 in Lcom/mysql/jdbc/ConnectionPropertiesImpl$ConnectionProperty;.storeTo
10-16 15:04:03.032      532-540/com.example.dev.mbstore I/dalvikvm﹕ Total arena pages for JIT: 11
10-16 15:04:03.232      532-535/com.example.dev.mbstore D/dalvikvm﹕ GC_CONCURRENT freed 167K, 3% free 10724K/11015K, paused 3ms+3ms
10-16 15:04:03.242      532-532/com.example.dev.mbstore I/dalvikvm﹕ Could not find method java.lang.management.ManagementFactory.getThreadMXBean, referenced from method com.mysql.jdbc.MysqlIO.appendDeadlockStatusInformation
10-16 15:04:03.242      532-532/com.example.dev.mbstore W/dalvikvm﹕ VFY: unable to resolve static method 7453: Ljava/lang/management/ManagementFactory;.getThreadMXBean ()Ljava/lang/management/ThreadMXBean;
10-16 15:04:03.242      532-532/com.example.dev.mbstore D/dalvikvm﹕ VFY: replacing opcode 0x71 at 0x0079
10-16 15:04:03.351      532-532/com.example.dev.mbstore I/System.out﹕ com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    +++ LOG: entry corrupt or truncated
10-16 15:04:03.351      532-532/com.example.dev.mbstore I/System.out﹕ The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Apparently he can’t find the Driver class but I put the Mysql plugin in the dependencies and had it compiled.

Related class:

public class DatabaseExport{
    private static Connection conn = null;

    public static void conectaDB(String url, String porta, String banco, String usuario, String senha)
    {
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection("jdbc:mysql://"+url+":"+porta+"/"+banco,usuario,senha);
        }catch(Exception e)
        {
            Exceptions.getException(e);
        }
    }
}
  • As far as I can see, you’re using Java EE package classes on Android, which is not allowed. Also the problem is in connection, he is not able to establish a connection. He even considered using a web service for a bank connection?

  • there was no way I had to make a webservice with php

2 answers

2

I do not know how you have the rest of the necessary settings so I will leave in a general way the steps to which you should be aware:

  1. Download the Mysql JDBC Connector (English) and include it in the build path of the Android project.

  2. Include what is necessary:

    import java.sql.Connection;
    
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.Statement;
    
  3. Ensure that the link code JDBC is in a AsyncTask, otherwise you can’t interact with the database.

  4. Ensure that permission is present INTERNET that is needed to open sockets, that is, in your manifest you should have:

    <uses-permission android:name="android.permission.INTERNET" />
    
  5. Perform a test to see if the connection went well or there are errors to resolve:

    try {
      Class.forName("com.mysql.jdbc.Driver");
      Connection con = DriverManager.getConnection(endereco, utilizador, password);
    
      /* Debug: */
      /* System.out.println("Ligação à BD com sucesso."); */
    }
    catch(Exception e) {
      e.printStackTrace();
    }
    
  • then I tried this but it seems that the android studio ta giving serious problems in this part, to migrating to the eclipse when finished put an answer on the fact.

1


Browser other questions tagged

You are not signed in. Login or sign up in order to post.