简体   繁体   English

将mysql-connector-java-5.1.38-bin粘贴到lib中-Android Studio

[英]pasting mysql-connector-java-5.1.38-bin into lib - Android Studio

I am trying to connect to a database with Java from Android Studio. 我正在尝试使用Android Studio中的Java连接到数据库。

When I create a brand new empty project and run it, the project runs fine. 当我创建一个全新的空项目并运行它时,该项目运行良好。 As soon as I paste mysql-connector-java-5.1.38-bin into the lib directory (app/lib) and then try to run the project, I get 2 errors. 一旦我将mysql-connector-java-5.1.38-bin粘贴到lib目录(app / lib)中,然后尝试运行该项目,就会出现2个错误。

Error:com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000) 错误:com.android.dx.cf.iface.ParseException:错误的类文件魔术(cafebabe)或版本(0034.0000)

Error:Execution failed for task ':app:transformClassesWithDexForDebug'. 错误:任务':app:transformClassesWithDexForDebug'的执行失败。

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\\Program Files\\Java\\jdk1.8.0_74\\bin\\java.exe'' finished with non-zero exit value 1 com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令'C:\\ Program Files \\ Java \\ jdk1.8.0_74 \\ bin \\ java.exe'完成,非零退出值1

I've also tried adding it as a dependency but I didn't think I needed to because {include=[*.jar], dir=libs} is already in the dependency list. 我也尝试将其添加为依赖项,但我认为我不需要这样做,因为{include = [*。jar],dir = libs}已经在依赖项列表中。

Thanks for reading 谢谢阅读

Does JDBC not work with Android? JDBC是否不适用于Android?

JDBC is infrequently used on Android, and I certainly would not recommend it. JDBC在Android上很少使用,我当然不推荐使用。

IMHO, JDBC is designed for high-bandwidth, low-latency, highly-reliable network connections (eg, desktop to database server, Web application server to database server). 恕我直言,JDBC专为高带宽,低延迟,高度可靠的网络连接(例如,台式机到数据库服务器,Web应用程序服务器到数据库服务器)而设计。 Mobile devices offer little of these, and none of them consistently. 移动设备几乎没有提供这些功能,而且也没有提供一致的功能。

If so, tell me what alternatives I should look into for remote MySQL database access. 如果是这样,请告诉我对于远程MySQL数据库访问应考虑哪些替代方法。

Create a Web service around your database and access that from Android. 在数据库周围创建一个Web服务,然后从Android访问该服务。

As side benefits, you improve security (vs. leaving your database open), can offload some business logic from the client, can better support other platforms (eg, Web or Web-based mobile frameworks), etc. 作为附带的好处,您可以提高安全性(与保持数据库打开状态相比),可以从客户端上卸载某些业务逻辑,可以更好地支持其他平台(例如,基于Web或基于Web的移动框架)等。

Referenced from this answer 这个答案引用

Android cannot connect directly to the database server. Android无法直接连接到数据库服务器。 Therefore we need to create a simple web service that will pass the requests to the database and will return the response. 因此,我们需要创建一个简单的Web服务,它将请求传递给数据库并返回响应。

So my suggestion is do not use JDBC jar file in android. 所以我的建议是不要在android中使用JDBC jar文件。

Check this answer for more details of the Execution failed for task :app transformClassesWithDexForDebug . 检查此答案以获取更多有关Execution failed for task :app transformClassesWithDexForDebug详细信息Execution failed for task :app transformClassesWithDexForDebug

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mysql-connector-java-5.1.38的.jar应该包含在哪个类路径中 - In which classpath should .jar of mysql-connector-java-5.1.38 be included “AWT-EventQueue-0”java.lang.NullPointerException 在 mysql.connector.java@5.1.38-bin/com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.8821324:94518) - "AWT-EventQueue-0" java.lang.NullPointerException at mysql.connector.java@5.1.38-bin/com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:2015) Java mysql错误:找不到或加载主类lib \\ mysql-connector-java-5.1.25-bin.jar - Java mysql Error: Could not find or load main class lib\mysql-connector-java-5.1.25-bin.jar mysql-connector-java-5.1.23-bin.jar未部署 - mysql-connector-java-5.1.23-bin.jar NOT deployed 错误:在具有mysql-connector-java-5.0.7-bin的JAR中 - Error: in JAR with mysql-connector-java-5.0.7-bin 找不到文件mysql-connector-java-5.1.13-bin.jar - Could not find file mysql-connector-java-5.1.13-bin.jar android JDBC mysql java 连接器应用程序:preDexDebug - android JDBC mysql java connector app:preDexDebug 我使用哪个MySQL连接器:mysql-connector-java-5.1.46.jar或mysql-connector-java-5.1.46-bin.jar有什么区别? - Which MySQL connector do I use: mysql-connector-java-5.1.46.jar or mysql-connector-java-5.1.46-bin.jar What is the difference? 在Mac上找不到MySQL,使用mysql-connector-java-5.1.13-bin.jar的Eclipse项目出现问题 - MySQL not found on Mac, problems with eclipse project using mysql-connector-java-5.1.13-bin.jar 使用外部库mysql-connector-java-5.1.24-bin.jar在Unix上编译Java项目 - Compiling a Java project on Unix using external library mysql-connector-java-5.1.24-bin.jar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM