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.jdbc.Driver
So How can I add The JDBC Driver to Android Studio ??
-
Download JDBC and extract the .jar file
- Open Android Studio and your project of interest
- Open your Left Panel, in the 1.Project Tab
- Right Click on your application module folder and go to New > Module and there Select Import .JAR/.AAR Package.
- 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:
- Right Click again on your application module folder and select Open Module Settings
- In the left navigation pane of the newly opened window, go to the category Modules and select app and then the Dependencies tab.
- There click on the green plus (+), and select Module Dependencies. Select the mysql module.
- Click OK, and close all the opened windows. A Synchronization process should take place once more.
- If everything has been done correctly, under your app module folder you should see a mysql-connector-java module folder.
- 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).