Monday, March 3, 2014

When ANDROID development database fuzzy query Chinese, not seized, is how is it?


FoodAdditivesAppActivity.java to AccuratelySearch.java-value
Value and the acquired input value input box is correct,
However in the database search fuzzy search Chinese, unable to search.
The number of inquiries and English can be.
SQL statement:
sql = "Select name, norm From additive Where name Like '%" + value + "%'";
value is the value entered in the input box by log.e ("value", value) values ​​correctly
incoming inspectionSQLITE database<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Database coding
Reply:
First look at the operation into sqllite
Reply:
This possibility, android applications top Chinese is utf coding, while the database is GBK, two encoding ASCII English and numbers are coming, coding, as can be found, is not the same character coding
Reply:
reference to the third floor czs_0_0_0_0 reply:
this possibility, android applications top Chinese is utf coding, while the database is GBK, two coding English and ASCII numbers are over, coding, as can be found, is not the same Chinese character encoding



temp = new String (value.getBytes (), "UTF-8");

But I after transcoding in the database search as search less,
Have tried a variety of coding
Reply:
You can do all of the code Tieshanglai
Reply:
In the database are not received, the statement that there is a problem
Reply:
Generally do not have arguments, are used? On behalf of the variables, look grammar
Reply:
reference to the 6th floor jeky198306 reply:
in the database are not received, the statement that there is a problem

You can search the database in English, but found not Chinese.
Reply:
references, 5th Floor czs_0_0_0_0 reply:
Tieshanglai all the code you can do


package com.Food.app;

import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import android.app.Activity;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class AccuratelySearch extends Activity {
private SQLiteDatabase db;
private String sql, value, temp;

public void onCreate (Bundle savedInstanceState) {

super.onCreate (savedInstanceState);
setContentView (R.layout.classfyresult);

db = SQLiteDatabase.openOrCreateDatabase (DBManager.DB_PATH + "/"
+ DBManager.DB_NAME, null);
value = (String) getIntent () getSerializableExtra ("value");.

try {
temp = new String (value.getBytes (), "UTF-8");
} Catch (UnsupportedEncodingException e1) {
/ / TODO Auto-generated catch block
e1.printStackTrace ();
}

sql = "Select name, norm From additive Where name Like '%" + temp + "%'";



/ / Check incoming values ​​
Log.e ("sql", sql);
Cursor c = db.rawQuery (sql, null);
c.moveToFirst ();
ArrayList > data = new ArrayList > ();
Map item;
for (int i = 0; i item = new HashMap ();
try {
item.put ("name", new String (c.getBlob (0), "GBK"));
item.put ("norm", new String (c.getBlob (1), "GBK"));
} Catch (UnsupportedEncodingException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
data.add (item);
c.moveToNext ();
}
c.close ();
db.close ();
ListView mListView01 = new ListView (this);
SimpleAdapter adapter = new SimpleAdapter (this, data,
R.layout.classfyresult, new String [] {"name", "norm"},
new int [] {R.id.TextView01, R.id.TextView02});
mListView01.setAdapter (adapter);
setContentView (mListView01);

}
}
Reply:
Logically speaking, there is no problem
But I checked the Internet about
lz can look
http://bbs.9ria.com/thread-16890-1-1.html
It says sqlite characters stored Although utf, but it is a word 6 bytes, if the time taken by the six bytes are taken out garbled.
I hope to help lz
Reply:
I also encountered this problem.
Adb shell used in this statement can be found in, but finding out the data in code execution, I am the egg pain.

Then online search, some say
------> Query to "SELECT * FROM table WHERE column LIKE N '% content%'", Chinese Fuzzy query successful!

I tried it, seemingly not. adb shell in not, plus N error. The code is not.
Reply:
Do not use '% "+ value +"%' "way. Try using the '%' +? +"% '"Way.
Reply:
2 and a half years, the problem still exists in this?

No comments:

Post a Comment