2016-10-08 3 views
0

나는 안드로이드 개발자가 아니라고 말하는 것으로 시작하고 싶습니다. 그래서 뭔가 분명하지 않은 것이 있으면 용서해주십시오.MySQL 데이터베이스에서 Android로 간단한 중국어 검색 Application

저는 Android Studio를 사용하여 사용자가 자신의 데이터베이스에서 항목을 표시 할 수있게 해주는이 상대적으로 간단한 App을 만듭니다. 각 테이블의 열 이름은 "ITEMID, PICURLS, DSCR, PRICE"입니다. 모든 테이블은 필요에 따라 값을 반환하지만 DSCR에서는 내가 입력 한 중국어 간체 문자 대신 항상 Questionmarks를 반환합니다. 이 설정은 다른 설정 (utf8_unicode_co, GB2312_bin, GB2312_chinese_ci, GBK_bin 및 GBK_chinese_ci)에 데이터 정렬을 설정하려고 시도한 결과로,이를 Google 검색 할 때마다 발견했습니다. 불행히도, 여전히 성공은 없습니다 ...

간단한 PHP 스크립트로 검색하면 HttpsURLConnection 및 BufferedReader를 사용하여 Android 애플리케이션에서 호출됩니다. 이것은 데이터베이스에서 송수신을 수행하는 응용 프로그램의 유일한 코드입니다.

if (command.equals("GETNEWESTITEMS")) { 
      try { 
       URL url = new URL("hidden_for_privacy_reasons"); 
       HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); 


       StringBuilder builder = new StringBuilder(); 
       builder.append(URLEncoder.encode("command", "UTF-8")); 
       builder.append("="); 
       builder.append(URLEncoder.encode(command, "UTF-8")); 
       builder.append("&"); 
       builder.append(URLEncoder.encode("category", "UTF-8")); 
       builder.append("="); 
       builder.append(URLEncoder.encode(category, "UTF-8")); 
       String urlParameters = builder.toString(); 

       connection.setRequestMethod("POST"); 
       connection.setDoOutput(true); 
       DataOutputStream dStream = new DataOutputStream(connection.getOutputStream()); 

       dStream.writeBytes(urlParameters); 
       dStream.flush(); 
       dStream.close(); 

       BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); 
       String line = ""; 
       StringBuilder responseOutput = new StringBuilder(); 

       while ((line = br.readLine()) != null) { 
        Log.e("DatabaseTask", line); 
        responseOutput.append(line); 
       } 
       br.close(); 

       echoData = responseOutput.toString(); 


      } catch (MalformedURLException e) { 
       e.printStackTrace(); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 

이이 특정 명령을 수행 내 PHP 스크립트의 일부분이 될 것입니다 (아마 가장 좋은 방법,하지만 모든 중국어 간체 문자를 제외하고 작동)

if ($command == "GETNEWESTITEMS") { 
     $category = $_POST["category"]; 
     $qry = "select * from ".$category." ORDER BY id DESC LIMIT 5"; 
     if ($result = mysqli_query($conn, $qry)) { 
      echo "succes&"; 
      while ($row = mysqli_fetch_assoc($result)) { 
       echo implode(',', $row).":"; 
      } 
     } else { 
      echo "failed&".mysqli_error($conn); 
     } 

유일한 것은 내가 그것이 내 응용 프로그램이 로그에 반환되는 전체 줄을 인쇄하기 때문에 내 게시물 요청에서 오는 응답을 읽는 방식과 관련이 있다고 생각할 수 있습니다. 그러나 이것이 사실인지 전혀 알 수 없습니다. 그것을 해결하는 방법.

모든 제안을 환영합니다!

EDIT_01

if ($command == "GETNEWESTITEMS") { 
     $category = $_POST["category"]; 
     $qry = ("set character_set_server='utf8'"); 
     $qry = "select * from ".$category." ORDER BY id DESC LIMIT 5"; 
     if ($result = mysqli_query($conn, $qry)) { 
      echo "succes&"; 
      while ($row = mysqli_fetch_assoc($result)) { 
       echo implode(',', $row).":"; 
      } 
     } else { 
      echo "failed&".mysqli_error($conn); 
     } 
+0

당신은 중국어 문자 저장 데이터베이스합니까? – Naz141

+0

그것은 보인다. phpMyAdmin을 열면 모든 한자가 여전히 있습니다. – sdieters

+0

이므로 모든 레코드를 선택하면 중국어 문자가'?????? '로 표시됩니다. – Naz141

답변

0

사용

$qry = ("set character_set_server='utf8'"); 

하여 아래 문 앞에

$qry = "select * from ".$category." ORDER BY id DESC LIMIT 5"; 
+0

나는 그것을 시도했지만 시각적으로 불행하게도 아무것도 변경되지 않았습니다. 나는 utf8_unicode_ci에 데이터 정렬을 다시 시도했지만 성공하지 못했습니다. 귀하의 제안을 오해 한 경우를 대비해서 EDIT_01 아래에 현재 코드가 게시되었습니다. @ Your-Common-Sense, 왜 이것이 정확한 복제물입니까? 나는이 주제가 제대로 기록 된 것을 보지 못했다. – sdieters

관련 문제