[英]MySql or phpMyAdmin gives null pointer if it contains special character
我使用了本教程: http : //www.helloandroid.com/tutorials/connecting-mysql-database
這真棒。 但是我得到了這個名字Eugène
但是當我嘗試從數據庫中取出這個名字時,它給出了一個nullPointer
,但是當我將其更改為Eugne
,它將顯示該名字。
是否可以從數據庫到android顯示/獲取諸如“è”之類的字符?
我閱讀了一些教程,但無法正常工作。
<?php
mysql_connect("127.0.0.1","root","root");
mysql_select_db("peopledata");
$q=mysql_query("SELECT * FROM people2 WHERE voornaam LIKE '%%'");
//$q=mysql_query("SELECT * FROM people WHERE voornaam ='""'");
while($e=mysql_fetch_assoc($q))
$output[]=$e;
print(json_encode($output));
mysql_close();
?>
這是我的android java部分:
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
android.util.Log.e("log_tag",
"Error converting result " + e.toString());
}
編輯1
08-22 16:24:56.935: I/log_tag(14424): id: 3, name: null;
但是它沒有顯示錯誤
找到了答案:把這一行: mysql_query("SET NAMES
utf8 ");
在連接數據庫之前。
來自:
mysql_connect("127.0.0.1","root","root");
mysql_select_db("peopledata");
至:
mysql_connect("127.0.0.1","root","root");
mysql_query("SET NAMES `utf8`");
mysql_select_db("peopledata");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.