【问题标题】:How to retrieve mysql data using volley with java in android without php?如何在没有 php 的 android 中使用 volley 和 java 检索 mysql 数据?
【发布时间】:2016-09-06 05:56:22
【问题描述】:

如何在没有 PHP 的 Android 中使用 Volley 和 Java 检索 MySql 数据?

【问题讨论】:

  • 纯代码编写请求在 Stack Overflow 上是题外话——我们希望这里的问题与特定编程问题有关——但我们很乐意帮助您自己编写!告诉我们what you've tried,以及您遇到的问题。这也将有助于我们更好地回答您的问题。
  • 你也可以在服务器上使用Java。
  • 删除了不必要的 cmets,减少了问号并添加了一些大写字母

标签: android mysql performance android-volley


【解决方案1】:

要与服务器通信,您必须用 java 编写 API。其中将包括数据库名称、用户名、访问密码、获取数据的 sql 查询。

StringRequest stringRequest = new StringRequest(Request.Method.POST, DB_URL,

                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        // responce may be String, JSONOnject, JSONArray. Handle with your own actions.
                },

                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // Error occurs in API(loop,TimeOutError,...)
                    }
                }){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError  {
                Map<String, String> params = new HashMap<>();
                // Map your Key and Value to match in the API to perform actions.
            }
        };

        RequestQueue requestQueue = Volley.newRequestQueue(getContext());
        requestQueue.add(stringRequest);

【讨论】:

    猜你喜欢
    • 2020-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-23
    • 2016-08-17
    • 2021-07-18
    • 2016-03-29
    相关资源
    最近更新 更多