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();