我如何从Android中的应用程序发送阿拉伯语单词并存储在阿拉伯语的mysql数据库中?

时间:2014-02-15 01:05:58

标签: java php android mysql unicode

我在Android中的应用程序接受阿拉伯语中的用户名并存储在服务器上的mysql数据库中但是从app发送到数据库时的名称,它存储为????

我在数据库中使用charset作为UTF-8并且web上的控制面板上的所有进程都可以,但是从app到数据库它还不行

从app到db的商店信息的asyntask是:

class InsertInfo extends AsyncTask<String, String, String> {

     @Override
        protected void onPreExecute() {
            super.onPreExecute();

        }

    @Override
    protected String doInBackground(String... arg0) {
        // TODO Auto-generated method stub
        namest=name.getText().toString();
        //emailst=email.getText().toString();
        mobilest=mobile.getText().toString();
        imgst=image_name;


        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("id", evid+""));
        params.add(new BasicNameValuePair("name",namest));
      //  params.add(new BasicNameValuePair("email", emailst));
        params.add(new BasicNameValuePair("mobile", mobilest));
        params.add(new BasicNameValuePair("imgurl", imgst));


     /*   JSONObject json = jsonParser.makeHttpRequest(urlinsert,
                "POST", params);*/


        try
        {
        HttpClient httpclient = new DefaultHttpClient();
        //HttpParams pa = new BasicHttpParams();
        //HttpProtocolParams.setContentCharset(pa, "utf-8");
            HttpPost httppost = new HttpPost(urlinsert);
           // httppost.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,  "application/json"));
            httppost.setEntity(new UrlEncodedFormEntity(params));
            HttpResponse response = httpclient.execute(httppost); 
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
            Log.e("pass 1", "connection success ");

    }
        catch(Exception e)
    {
            Log.e("Fail 1", e.getMessage());
            Toast.makeText(getApplicationContext(), "Invalid IP Address",
            Toast.LENGTH_LONG).show();
    }  

         try
         {
             BufferedReader reader = new BufferedReader
            (new InputStreamReader(is,"UTF-8"),8192);
             StringBuilder sb = new StringBuilder();
             while ((line = reader.readLine()) != null)
        {
                 sb.append(line + "\n");
             }
             is.close();
             result = sb.toString();
        Log.e("pass 2", "connection success ");
    }
         catch(Exception e)
    {
             Log.e("Fail 2", e.toString());
    }  


         try
            {
                    JSONObject json_data = new JSONObject(result);
                    code=(json_data.getInt("code"));

                    if(code==1)
                    {
                Toast.makeText(getBaseContext(), "Inserted Successfully",
                    Toast.LENGTH_SHORT).show();
                    }
                    else
                    {
                 Toast.makeText(getBaseContext(), "Sorry, Try Again",
                    Toast.LENGTH_LONG).show();
                    }
            }
            catch(Exception e)
            {
                    Log.e("Fail 3", e.toString());
            }

        return null;
    }

     protected void onPostExecute(String file_url) {
            // dismiss the dialog once product uupdated

        }

}

我正在尝试很多方法,而且每次我都使用UTF-8,但它不能正常工作,请你在这种情况下帮助我:(

2 个答案:

答案 0 :(得分:0)

如果您没有在开始阶段启动utf-8,那么您可能必须从服务器一直走下去 - &gt;连接 - &gt;数据库 - &gt;表 - &gt;查询

  1. MySQL charset:UTF-8 Unicode(utf8)
  2. MySQL连接排序规则:utf8_general_ci
  3. 您的数据库和表排序规则设置为:utf8_general_ci或utf8_unicode_ci
  4. PHP代码:

    1. mysql_query(“SET NAMES'utf8'”);
    2. mysql_query('SET CHARACTER SET utf8');
    3. 更新

      您是否还取消了代码中的协议行?

      //HttpParams pa = new BasicHttpParams();    
      //HttpProtocolParams.setContentCharset(pa, "utf-8");
      

答案 1 :(得分:0)

用于创建数据库以接受所有类型的语言和字体的命令。

    function getQueryParameters(str) {
      return (str || document.location.search).replace(/(^\?)/,'').split("&").map(
        function(n){
          return n = n.split("="),this[n[0]] = n[1],this;
        }.bind({}))[0];
  }

var url = "&company_state[AKERSHUS]=AKERSHUS&company_state[AKERSHUS[]=ASKER&company_state[SOGN+OG+FJORDANE]=SOGN+OG+FJORDANE&company_state[SOGN+OG+FJORDANE][]=ASKVOLL";

var arr = getQueryParameters(url);


for(var a in arr){
  console.log("key:" , a.substr('company_state'.length), "   value:" ,  arr[a]);
}