Sqlite3 command line to view Chinese garbled problem solved, sqlite3 Chinese
The SQLite library contains a command line named sqlite3, which allows you to manually enter and execute SQL commands for the SQLite database. The database we create through the program is generally located in the package/databases of the content class set by/data/program db. In this path, execute the sqlite3 database name to enter the SQL command line mode, perform database operations.
If this parameter is not set, the Chinese characters are garbled during query in the command line window. This is because the default Character Set of cmd is gbk, and sqllite adopts the default encoding of UTF-8.
If you want to solve this problem, there are two solutions:
[1] command setting method:
(1) Exit dos or reopen it in the CMD window. Enter:
chcp 65001
Then press enter to confirm
Note that 65001 is the encoding setting for Unicode (UTF-8) 65001, And the setting for Chinese Simplified (GB2312) is 936
(2) Right-click the title bar of the command line and choose Properties> font to change the font to Lucida Console. Select the current window to be valid or apply to all windows.
[2] registry settings:
(1) Open the Registry Editor (regedit) and expand to the following location:
HKEY_CURRENT_USER \ Console \ unzip systemroot1__system32_cmd.exe
Change the CodePage item to a decimal value.
437 (English ),
65001 (UTF-8 ),
936 (GBK ).
This will enable the character set after cmd to be modified. The character set changed using the chcp command will change to the default value after the cmd window is opened.
(2) Right-click the title bar of the command line and choose Properties> font to change the font to Lucida Console. Select the current window to be valid or apply to all windows.
Supplement the usage of the chcp command:
Function of chcp: Switch the character format chcp 65001 # Replace it with the UTF-8 code page chcp 936 # Replace it with the default gbkchcp 437 # The default value of American English is gbk,
Android sqlite3 garbled Chinese Characters
The encoding used for inserting characters must be the same as that used for reading characters, that is:
Assume that the data in the database is inserted using android code in GB2312 encoding format, for example:
Db.exe cSQL ("insert into question_tb values (?,?,?,?,?,?,?) ", New String (val," gb2312 "); insert to table:
"Create table if not exists question_tb (" + "code int," + "is_finished int," + "is_english int," + "pic_name varchar (64 ), "+" ans_back BLOB, "+" ans_true varchar (64), "+" info int "+") "; read:
Byte [] val = cursor. getBlob (cursor. getColumnIndex ("ans_back"); String sn; try {sn = new String (val, "gb2312");} catch (UnsupportedEncodingException e) {e. printStackTrace () ;}that is, insert and read are either converted or not done (android default UTF-8 format ).
Android SQLITE inserts Chinese characters and garbled characters. How can this problem be solved?
Because SQLite supports UTF-8 encoding, it should be converted to UTF-8 when generating SQL statements, insert after it is no problem.