android JDBC mysql java connector app:preDexDebug

前端 未结 3 1381
無奈伤痛
無奈伤痛 2020-12-21 07:13


Im trying to learn how to use the JDBC to connect a application to a mysql database.
Im using the Android Studio.
I downloaded \"mysql-connector-java-5.1.37\" f

相关标签:
3条回答
  • 2020-12-21 07:24

    Try to sync your project Tools -> Android -> Sync Project with Gradle Files

    And then rebuild your project: build -> rebuild project

    0 讨论(0)
  • 2020-12-21 07:27

    I had the same issue and the problem was in the mysql-connector-java-5.1.37.jar file. I downloaded an older version (mysql-connector-java-3.0.17-ga-bin.jar) from here and worked like a charm.

    To get the connection use:

    Class.forName("com.mysql.jdbc.Driver").newInstance();
    String connection = "jdbc:mysql://"+ your_ip + ":"+ your_port +"/"+ database_name;
    conn = DriverManager.getConnection(connection, user, pass); 
    

    Just in case, don't forget to compile it in your build.gradle:

    dependencies {
        //other stuff
        compile files('libs/mysql-connector-java-3.0.17-ga-bin.jar')
    }
    

    PD: This only works if you use the connection from and AsyncTask

    0 讨论(0)
  • 2020-12-21 07:30

    Because Distributed mysql-connector-java-5.1.37-bin.jar is compiled for Java1.8, current Android dex compiler cannot recognize it.

    $ javap -v com/mysql/jdbc/JDBC42Helper.class| grep "major version"
      major version: 52
    

    On the oher hand, mysql-connector-java-5.1.36.jar is compiled for Java1.6.

    $ javap -v com/mysql/jdbc/JDBC4Connection.class |grep "major version"
      major version: 50
    

    5.1.37 supports JDBC4.2, so requires Java1.8.

    0 讨论(0)
提交回复
热议问题