Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Mysql JDBC Driver to android studio

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 ??

like image 636
user3814438 Avatar asked Dec 06 '22 01:12

user3814438


1 Answers

  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).

like image 191
Rapsoulis Avatar answered Dec 10 '22 13:12

Rapsoulis