开发者

android sql data

I am new to android and I want to communicate with the server to transfer sql data. I have read posts using raw http and also referred Unlocking Android chapter 6. But are there more 开发者_StackOverflow社区clearer steps? Like where should I start my reading and what examples I should be looking at?

My end goal is to send and receive data from a sql database on a online server. I know i have to use a medium like php to perform query but my confusion is more on the android side.


Well there are alot of way you could accomplish this. Here is one.

  1. Write a backend in PHP (or the language of your choice) to run SQL queries and then take that data and serialize it into JSON.
  2. Then in the Android app request the Url of the PHP file.
  3. Use GSON or another JSON parser to parse the JSON into objects.
  4. Display the object on App (List, Map ...)

If you are having trouble with the Android side of it I would recommend looking at some documentation.

EDIT Code for building a url using a map where the keys are the get parameters and the values are the value of the get parameters.

if (vars != null) {
    Iterator<String> itr = vars.keySet().iterator();
    boolean first = true;

    // Append them to the url
    while (itr.hasNext()) {
        String key = itr.next();
        if (first) {
            builder.append("?" + key + "=" + vars.get(key));
            first = false;
        } else {
            builder.append("&" + key + "=" + vars.get(key));
        }
    }
}
builder.toString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜