如何将 Mysql JDBC 驱动程序导入到 android studio
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24784871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Mysql JDBC Driver to android studio
提问by user3814438
I want to connect to remote sql database via jdbc I work on Android Studio But when executing I got this error
我想通过 jdbc 连接到远程 sql 数据库我在 Android Studio 上工作但是在执行时我收到了这个错误
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
So How can I add The JDBC Driver to Android Studio ??
那么如何将 JDBC 驱动程序添加到 Android Studio 中?
回答by Rapsoulis
- Download JDBCand extract the .jarfile
- Open Android Studio and your project of interest
- Open your Left Panel, in the 1.ProjectTab
- Right Click on your application module folder and go to New> Moduleand there Select Import .JAR/.AAR Package.
- In the first field you must insert the directory of the previously extracted .jarfile. You can browse your folders by clicking on the far right icon with the 3 dots (...)
- 下载 JDBC并解压.jar文件
- 打开 Android Studio 和您感兴趣的项目
- 在1.Project选项卡中打开左面板
- 右键单击您的应用程序模块文件夹,然后转到New> Module,然后选择Import .JAR/.AAR Package。
- 在第一个字段中,您必须插入先前提取的.jar文件的目录。您可以通过单击最右侧带有 3 个点(...) 的图标来浏览您的文件夹
Once you have selected the .jarfile and your project Synchronizesyou can move on to the next steps:
选择.jar文件和项目同步后,您可以继续执行以下步骤:
- 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 Modulesand select appand then the Dependenciestab.
- There click on the green plus (+), and select Module Dependencies. Select the mysqlmodule.
- Click OK, and close all the opened windows. A Synchronizationprocess should take place once more.
- If everything has been done correctly, under your app module folderyou should see a mysql-connector-javamodule folder.
- Don't forget to include the classes you want in your code.
- 再次右键单击您的应用程序模块文件夹并选择打开模块设置
- 在新打开的窗口的左侧导航窗格中,转到类别模块并选择应用程序,然后选择依赖项选项卡。
- 单击绿色加号 ( +),然后选择Module Dependencies。选择mysql模块。
- 单击OK,并关闭所有打开的窗口。一个同步的过程应该发生一次。
- 如果一切都正确完成,在您的应用程序模块文件夹下,您应该会看到一个mysql-connector-java模块文件夹。
- 不要忘记在代码中包含您想要的类。
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).
故障排除
在我的情况下,我不得不卸载模块并重新安装它。原因是该模块是用 Java 1.8 而不是 1.7 编译的(目前 Android Studio ver:1.5.1 支持)。
回答by AlonsoFloo
You can see the official site of MySQL to download the [JDBC][2].
可以到MySQL官网下载[JDBC][2]。
Then you only need to add the library to Android Studio like any other library.
然后你只需要像任何其他库一样将该库添加到 Android Studio。