如何将 Mysql JDBC 驱动程序导入到 android studio [英] How to Mysql JDBC Driver to android studio

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

问题描述

我想通过jdbc连接远程sql数据库我在 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  

那么如何将 JDBC 驱动程序添加到 Android Studio 中??

So How can I add The JDBC Driver to Android Studio ??

推荐答案

  1. 下载 JDBC 并解压 .jar 文件
  2. 打开 Android Studio 和您感兴趣的项目
  3. 1.Project 选项卡中打开左面板
  4. 右键单击您的应用程序模块文件夹并转到 New > Module,然后选择 Import .JAR/.AAR 包.
  5. 在第一个字段中,您必须插入之前提取的 .jar 文件的目录.您可以通过单击最右侧带有 3 个点的图标来浏览您的文件夹(...)
  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 (...)

一旦您选择了 .jar 文件和您的项目同步,您就可以继续下一步:

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

  1. 再次右键单击您的应用程序模块文件夹并选择打开模块设置
  2. 在新打开窗口的左侧导航窗格中,转到类别模块并选择应用,然后选择依赖项标签.
  3. 点击绿色加号 (+),然后选择 Module Dependencies.选择 mysql 模块.
  4. 点击确定,然后关闭所有打开的窗口.应该再次进行同步过程.
  5. 如果一切正常,在您的 app 模块文件夹下,您应该会看到一个 mysql-connector-java 模块文件夹.
  6. 不要忘记在代码中包含您想要的类.
  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.

疑难解答
在我的情况下,我不得不卸载模块并重新安装它.原因是该模块是用 Java 1.8 而不是 1.7 编译的(目前 Android Studio ver:1.5.1 支持).

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 studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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