(Android: SQLite 3) Single-host SQLite Database

Source: Internet
Author: User

Steps

1. Prepare the SQLite Database

Note: Create or copy a database, open it, and execute the following two SQL statements in sequence (set the current location without an error)

Create   Table "Android_metadata" ("locale" Text   Default   ' Zh_cn ' ) Insert   Into "Android_metadata" Values ( ' Zh_cn ' )

 

2. Put the SQLite database file in the assets folder.

Note: The SQLite database size must be smaller than 1 MB.

 

3. the android client generates database files.

 Code Code highlighting produced by actipro codehighlighter (freeware) http: //  Www.codehighlighter.com/--> private sqlitedatabase opendatabase () {  Try  {  //  Obtain the absolute path of the dictionary. DB File String databasefilename = database_path + "/" + Database_filename; file dir = New  File (database_path );  //  If the/sdcard/dictionary directory exists, create this directory.              If (! Dir. exists () dir. mkdir ();  // If it does not exist in the/sdcard/dictionary directory  //  The dictionary. DB file is copied from the res \ raw directory  //  Directory of the SD card (/sdcard/dictionary)              If (! ( New  File (databasefilename). exists ()){  //  Obtains the inputstream object that encapsulates the dictionary. DB file. Inputstream is = Getresources (). openrawresource (R. Raw. dictionary); fileoutputstream fos =New  Fileoutputstream (databasefilename );  Byte [] Buffer = New   Byte [8192 ];  Int Count = 0 ;  //  Start copying the dictionary. DB File                  While (COUNT = is. Read (buffer)> 0 ) {FOS. Write (buffer, 0, Count);} FOS. Close (); is. Close ();}  //  Open the dictionary. DB file in the/sdcard/dictionary directory Sqlitedatabase database = Sqlitedatabase. openorcreatedatabase (databasefilename,  Null  );  Return  Database ;}  Catch  (Exception e ){}  Return   Null ;} 

 

Appendix:

Android Market of science back words-Level 4 edition: http://static.apk.hiapk.com/html/2012/07/719368.html

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.