Android commandid · cyclö®Ê Ó SQLite Ê â (db Ä ä¼ þ)

Source: Internet
Author: User

Android commandid · ~ö~~ó SQLite ~~~~â (db ~ä)

~Ú~~~~ö~£ ************************************************************** ímahathé ª {« ä äzomé ë Ä ä~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{{{| Ó Ã µädb Ä ä¼ Ï Â Ê Ó £ £.

'Úâ ë ° U. µ µ£ £ ************************************************************

Zookeeper **************************************************************

1. ''please raw ~ä~~%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%°


2. & apos; "> public class DBOpenHelper {private final int BUFFER_SIZE = 400000; public static final String DB_NAME =" idiom. db "; // ± £' æ µäê String ý Ý â Ä ä¼ þ public û public static final String PACKAGE_NAME =" cn.edu. bzu. happy "; // Ó µ µä° ü à public static final String DB_PATH ="/data "+ Environment. getDataDirectory (). GetAbsolutePath () + "/" + PACKAGE_NAME + "/databases "; // Ú úramö» úà ï '{· Å ý ¾ Ý â {%*****» öã // sdcard µäâ ¾ ¶ (ú úandroid 4.4 öyang²» ° {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%) // public static final String DB_PATH = Environment. getExternalStorageDirectory (). getAbsolutePath () + "/idiom"; private Context context; public DBOpenHelper (Context context) {this. context = context;} public SQLiteDatabase openDatabase () {try {File myDataPath = new File (DB_PATH); if (! MyDataPath. exists () {myDataPath. mkdirs (); // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%, when using ''{}string dbfile = myDataPath + "/" + DB_NAME; if (! (New File (dbfile ). exists ())) {// zookeeper ~~â Ä ä~~~~çen'~~ú£;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Ð µgateè £;%%%%%%%%%%%%%%%%%%%%%%â InputStream is = context. getResources (). openRawResource (R. raw. idiom); // ó{µ***********â FileOutputStream fos = new FileOutputStream (dbfile); byte [] buffer = new byte [BUFFER_SIZE]; int count = 0; while (count = is. read (buffer)> 0) {fos. write (buffer, 0, count);} fos. close (); is. close ();} SQLiteDatabase db = SQLiteDatabase. openOrCreateDatabase (dbfile, null); return db;} catch (FileNotFoundException e) {Log. e ("Database", "File not found"); e. printStackTrace ();} catch (IOException e) {Log. e ("Database", "IO exception"); e. printStackTrace ();} return null ;}}
Ê Ó £°

public class TestDao {private DBOpenHelper dbHelper;public TestDao (Context context) {dbHelper = new DBOpenHelper(context);}public List
 
   getAllTests() {List
  
    animals = new ArrayList
   
    ();SQLiteDatabase sqLiteDatabase = dbHelper.openDatabase();Cursor cursor = sqLiteDatabase.rawQuery("select * from test", null);While(cursor.moveToNext()){//»ñÈ¡ÄãµÄÊý¾Ý}}}
   
  
 

TestDao  test = new TestDao();test.getAllTests();




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.