android JDBC mysql java connector app:preDexDebug

前端 未结 3 1394
無奈伤痛
無奈伤痛 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: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

提交回复
热议问题