如何使用 Mysql JDBC 驱动程序连接 Android 和 MySQL [英] How to connect Android with MySQL using Mysql JDBC driver

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

问题描述

我想从 MySQL 中的表中获取数据并在 TextView 中显示它,但是当我尝试连接数据库时遇到了一些问题.
我在 Android 上使用 Eclipse,当我尝试从 Java 项目中的 MySQL 获取数据时它可以工作,但是当我使用 Android 项目时它不起作用.
有谁知道如何使用 MySQL JDBC 驱动程序将 MySQL 与 Android 项目连接起来?
或者给我其他建议如何将 Android 项目与 MySQL 连接?

I want to get data from table in MySQL and to show it in TextView, but I have some problems when I try to connect with database.
I'm using Eclipse for Android, and when I try to get data from MySQL in Java Project it works, but when I use Android Project it doesn't work.
Does anyone know how can I connect MySQL with Android Project using MySQL JDBC driver?
Or to give me other advice how to connect Android Project with MySQL?

推荐答案

Android 默认不支持 MySQL.它有一个内置数据库,即 SQLite.如果您尝试远程访问 MySQL 数据库,您应该使用任何标准 Web 服务公开该数据库的接口.例如,您可以在使用 Java/PHP 等和 MySQL 连接器编写的服务器端创建 RESTful Web 服务.(你已经完成了!)并且您的 Android 应用可以使用使用此网络服务生成的 URL 与此服务通信.

Android by default does not support MySQL. It has an in-built database i.e SQLite. If you are trying to access MySQL database remotely, you should expose interface to this database with any standard web service. E.g you could create RESTful Web Service on Server Side which is written using Java/PHP etc. and MySQL Connector. (Which you have already done!) And your Android App could talk to this service with the URL generated using this web service.

同样,这个问题之前已经重复过了,所以你可以检查这些解决方案.

Again, this question has been repeated previously, so you can check those solutions.

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

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