dtp19819 2014-02-20 05:15
浏览 45

从Android应用程序到mysql数据库的阿拉伯语文本

I have some problem with parsing arabic text to mysql database. Here is what I do:

  1. Parse text from app to php script

    String address = ListActivity.urlZapis;
    try {
        address +="?lp=" + detal.lp + "&date=" + detal.date + "&name=" + URLEncoder.encode (detal.name, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }
    
    try {
    URI uriAddress = new URI(address.replace(" ", "%20"));
    address=uriAddress.toString();
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(address);
    
    httpClient.execute(httpPost);
    
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    } catch (ClientProtocolException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } catch (URISyntaxException e) {
    e.printStackTrace();
    }
    
  2. in php file I connect to mysql and send data

$connect = mysqli_connect("$host", "$username", "$password", "$db_name");

if(mysqli_connect_errno($connect))
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");

Then I see something like this in my phpmyadmin: name - ماكروي٠وكولار instead of arabic text. Collation of mysql is set to utf8_general_ci. When I enter arabic text by phpmyadmin, everything works fine. It appears in my app correctly, so I am sure there is something wrong with sending it to db.

  • 写回答

4条回答 默认 最新

  • douyi0902 2014-02-20 05:22
    关注

    If you are using eclipse:

    right click right-click on your project. Go to Properties-->Resource--->Text File encoding--->other-->UTF-8

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?