How to Mysql JDBC Driver to android studio

前端 未结 2 615
误落风尘
误落风尘 2020-12-04 00:33

I want to connect to remote sql database via jdbc I work on Android Studio But when executing I got this error

java.lang.ClassNotFoundException: com.mysql.         


        
相关标签:
2条回答
  • 2020-12-04 00:38

    You can see the official site of MySQL to download the [JDBC][2].

    Then you only need to add the library to Android Studio like any other library.

    0 讨论(0)
  • 2020-12-04 00:44
    1. Download JDBC and extract the .jar file
    2. Open Android Studio and your project of interest
    3. Open your Left Panel, in the 1.Project Tab
    4. Right Click on your application module folder and go to New > Module and there Select Import .JAR/.AAR Package.
    5. In the first field you must insert the directory of the previously extracted .jar file. You can browse your folders by clicking on the far right icon with the 3 dots (...)

    Once you have selected the .jar file and your project Synchronizes you can move on to the next steps:

    1. Right Click again on your application module folder and select Open Module Settings
    2. In the left navigation pane of the newly opened window, go to the category Modules and select app and then the Dependencies tab.
    3. There click on the green plus (+), and select Module Dependencies. Select the mysql module.
    4. Click OK, and close all the opened windows. A Synchronization process should take place once more.
    5. If everything has been done correctly, under your app module folder you should see a mysql-connector-java module folder.
    6. Don't forget to include the classes you want in your code.

    Troubleshooting
    In my case I had to uninstall the module and re-install it. The reason was that the module was compiled with Java 1.8 instead of 1.7 (currently supported by Android Studio ver:1.5.1).

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