如何MySQL JDBC驱动程序到Android工作室 [英] How to Mysql JDBC Driver to android studio

查看:2805
本文介绍了如何MySQL JDBC驱动程序到Android工作室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接到通过JDBC远程SQL数据库
我在Android工作室工作
但在执行时,我得到这个错误

 抛出java.lang.ClassNotFoundException:com.mysql.jdbc.Driver

所以,我如何添加JDBC驱动程序到Android工作室??


解决方案

  1. 下载JDBC 并提取的的.jar 的文件

  2. 开启Android的工作室和你感兴趣的项目

  3. 打开你的左侧面板中,在一,项目的标签

  4. 右键点击您的应用程序模块文件夹,然后转至的>的模块并有选择 导入.JAR / .AAR包装

  5. 在第一个字段必须插入pviously提取 的.jar 文件中的$ P $的目录。您可以通过点击最右边的图标有三个点浏览你的文件夹 (...)

一旦你选择了 的.jar 文件和你的项目的同步的你可以移动到下一个步骤:


  1. 右键你的应用程序文件夹中的模块再次点击,选择的打开模块设置

  2. 在新打开的窗口的左侧导航窗格中,转到类别的模块的并选择 应用,然后在 依赖标签。

  3. 有点击绿色加号( + ),并选择 模块依赖。选择的的mysql 的模块。

  4. 单击确定,然后关闭所有打开的窗口。 A 同步过程应该发生一次。

  5. 如果一切都已经做得正确,你的应用程序模块的文件夹的你应该看到的使用mysql-connector-java的的模块文件夹下。

  6. 请不要忘记,包括你在code想要的类。

故障排除结果
在我而言,我不得不卸载模块并重新安装。原因是该模块与Java 1.8,而不是1.7(目前由Android版本工作室支持:1.5.1)编译。

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

解决方案

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

这篇关于如何MySQL JDBC驱动程序到Android工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆