使用MySQL与AndroidMySQL、Android

由网友(旧事酒浓.)分享简介:我想创建一个Android应用程序,连接到MySQL数据库。有没有一种简单的方法来做到这一点?也许,我已经错过了一个指导?这似乎是一个共同的任务,但由于某种原因,我无法找到关于它的信息。I'm trying to create an Android App that connects to a MySQL data...

我想创建一个Android应用程序,连接到MySQL数据库。有没有一种简单的方法来做到这一点?也许,我已经错过了一个指导? 这似乎是一个共同的任务,但由于某种原因,我无法找到关于它的信息。

I'm trying to create an Android App that connects to a MySQL database. Is there an easy way to do this? Maybe a guide that I have missed? This seems like a common task but for some reason I can't find much information about it.

推荐答案

您需要两样东西

Web服务 客户端

Web服务: 这基本上是一个网站,将得到MySQL的信息,并将其显示为JSON。您可以使用XML或别的东西,但 JSON 已被证明是最简单的我。

Web service: This is basically a website, that will get information from MySQL and display it as JSON. You can use XML or something else, but JSON has proven to be the easiest for me.

PHP和放大器; MySQL的教程: http://www.w3schools.com/php/php_mysql_intro.asp

PHP & MySQL tutorial: http://www.w3schools.com/php/php_mysql_intro.asp

我会假设你可以做到这一点,它不是那么难。你usualy得到的是从数据库中一个数组。您可以使用该数组来使JSON出来的,用

I will assume you can do that, it's not all that hard. What you usualy get is an array from database. You use that array to make JSON out of it, using

<?php
    echo json_encode($my_array);
?>

你将得到的是这样的:

What you will get is something like this:

{
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
}

客户端:到目前为止,我只用库名为 GSON ,这对我来说真是棒极了。我想你会发现所有的例子,对如何使用它。它的作用是读取JSON通过URL您提供并填补了你的对象。

Client: So far I have only used library called GSON, and it worked great for me. I think you will find all examples there on how to use it. What it does is read that JSON through URL you have provided and fills up your objects.

阅读全文

相关推荐

最新文章