安卓SQLite數(shù)據(jù)庫框架設(shè)計_第1頁
安卓SQLite數(shù)據(jù)庫框架設(shè)計_第2頁
安卓SQLite數(shù)據(jù)庫框架設(shè)計_第3頁
安卓SQLite數(shù)據(jù)庫框架設(shè)計_第4頁
安卓SQLite數(shù)據(jù)庫框架設(shè)計_第5頁
已閱讀5頁,還剩19頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、安卓SQLite數(shù)據(jù)庫框架設(shè)計安卓SQLite數(shù)據(jù)庫框架設(shè)計北京科技大學(xué)摘要:Android作為移動系統(tǒng)的霸主,無數(shù)的Android開發(fā)人員夜以繼日的開發(fā)安卓應(yīng)用,使得安卓應(yīng)用數(shù)量與日俱增,豐富多樣的應(yīng)用服務(wù)于人們的生活工作學(xué)習(xí),這要?dú)w功于安卓應(yīng)用開發(fā)的低成本和Android框架的易上手。而SQLite作為Android框架內(nèi)置的數(shù)據(jù)庫,更是為安卓應(yīng)用的開發(fā)提供了有效實用的數(shù)據(jù)存儲功能,SQLite,是一款輕型的數(shù)據(jù)庫,是遵守ACID的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),它包含在一個相對小的C庫中。它是D.RichardHipp建立的公有領(lǐng)域項目。它的設(shè)計目標(biāo)是嵌入式的,而且目前已經(jīng)在很多嵌入式產(chǎn)品中使用了

2、它,它占用資源非常的低,在嵌入式設(shè)備中,可能只需要幾百K的內(nèi)存就夠了。雖然SQLite擁有比較好的性能,但是對于習(xí)慣于MVC框架的開發(fā)人員來說并不習(xí)慣于直接書寫sql語句并通過exesql方法實現(xiàn),然而現(xiàn)在網(wǎng)絡(luò)上并沒有較好的SQLite框架。本著精益求精的精神,筆者要模仿ThinkPHP的數(shù)據(jù)庫的框架寫一個基于SQLite的數(shù)據(jù)庫框架。關(guān)鍵字:SQLite,框架,Android開發(fā)1ThinkPHP框架1.1ThinkPHP框架介紹ThinkPHP是為了簡化企業(yè)級應(yīng)用開發(fā)和敏捷WEB應(yīng)用開發(fā)而誕生的。是標(biāo)準(zhǔn)的MVC框架,ThinkPHP從誕生以來一直秉承簡潔實用的設(shè)計原則,在保持出色的性能和至

3、簡的代碼的同時,也注重易用性。并且擁有眾多原創(chuàng)功能和特性,在社區(qū)團(tuán)隊的積極參與下,在易用性、擴(kuò)展性和性能方面不斷優(yōu)化和改進(jìn)。1.2ThinkPHP數(shù)據(jù)庫框架介紹1.2.1框架結(jié)構(gòu)框架結(jié)構(gòu)圖如圖1所示:圖1:ThinkPHP框架結(jié)構(gòu)圖Application文件夾下放模塊,比如Common和Home分別是公共模塊和缺省模塊。Home文件夾下是標(biāo)準(zhǔn)的MVC框架,如圖所示,Home文件夾下的Controller是控制器存放位置,Model是模型存放位置,View是視圖存放位置。而我們要使用數(shù)據(jù)庫就必須要用到Model模形。1.2.2數(shù)據(jù)庫的配置首先在ThinkPHP/Conf/conwention.p

4、hp文件里配置好數(shù)據(jù)庫,如下:1.    'DB_TYPE' => 'mysql', / 數(shù)據(jù)庫類型2. 'DB_HOST' => 'localhost', / 服務(wù)地址3. 'DB_NAME' => 'test', / 數(shù)據(jù)庫名4. 'DB_USER' => 'liangdi', / 用戶名5. 'DB_PWD' => '*', / 數(shù)據(jù)庫密碼6. 'DB_PORT'

5、=> '3306', /端口號 1.2.3數(shù)據(jù)庫使用要使用數(shù)據(jù)庫,就必須給每張表生成一個表的模型,放在Model文件夾下,如數(shù)據(jù)庫里有tp_user_info表,則要寫以下的這個模形:7. <?php8. namespace CommonModel;9. use ThinkModel;10.11. class UserinfoModel extends Model12. 13. /protected $connection='DB_CONFIG2'14. protected $trueTableName = 'tp_user_inf

6、o'15. 16. public function fetch_all()17. return $this->where("id>0")->select();18. 19. 20. public function fetch_by_id($id)21. return $this->where("id = ?",$id)->select();22. 23. 這個數(shù)據(jù)表類要繼承Model,可以在里面定義數(shù)據(jù)表的名和主鍵字段以及字段數(shù)組,這里只用$trueTableName定義了表名。然后使用繼承類Model里的where

7、()和find()、select()等方法自定義自己想要的方法,比如fetch_by_id()方法定義了通過字段id的值返回查詢結(jié)果。接下來要在控制器里通過D()函數(shù)實例化上面的數(shù)據(jù)表類,并使用fetch_by_id()函數(shù)即可返回結(jié)果,如下所示:24. <?php25. namespace HomeController;26. use ThinkController;27. use Common;28. class IndexController extends Controller 29. public function index()30. $this->show('

8、<style type="text/css".','utf-8');31. 32. public function dbtest()33. $userinfo=D("Common/Userinfo");34. $res=$userinfo->fetch_all();35. $this->assign('usif',$res);36. $this->display();37. $userinfo=D("Common/Userinfo");工廠模式返回實例化的Userinfo

9、Model類。$res=$userinfo->fetch_by_id(2);調(diào)用fetch_by_id()函數(shù)查詢id為2的記錄并返回一個二維數(shù)組。以上就是ThinkPHP中數(shù)據(jù)庫的簡單使用。1.3ThinkPHP數(shù)據(jù)庫框架評價ThinkPHP數(shù)據(jù)庫框架優(yōu)點:(1) 只需要配置數(shù)據(jù)庫信息,以及定義對應(yīng)的數(shù)據(jù)表類,就可以實例化表類對數(shù)據(jù)庫進(jìn)行操作,不需要理會數(shù)據(jù)庫的連接。(2) 對每個表定義表類使得系統(tǒng)的結(jié)構(gòu)清晰,易于擴(kuò)展和修改。(3) 不需要定義sql語句,使用表類的繼承類Model類里封裝好的where()、select()、order()和insert()以及update()等方法傳

10、入?yún)?shù)進(jìn)行數(shù)據(jù)庫操作,對防止SQL注入攻擊有一定的效果,并且使得查詢結(jié)構(gòu)清晰。2SQLite的一般使用2.1SQLite一般情況現(xiàn)在的主流移動設(shè)備像Android、iPhone等都使用SQLite作為復(fù)雜數(shù)據(jù)的存儲引擎,在我們?yōu)橐苿釉O(shè)備開發(fā)應(yīng)用程序時,也許就要使用到SQLite來存儲我們大量的數(shù)據(jù),所以我們就需要掌握移動設(shè)備上的SQLite開發(fā)技巧。對于Android平臺來說,系統(tǒng)內(nèi)置了豐富的API來供開發(fā)人員操作SQLite,我們可以輕松的完成對數(shù)據(jù)的存取。ThinkPHP這種MVC架構(gòu)和PHP語言的結(jié)合使得數(shù)據(jù)庫操作簡單而方便,而在Android開發(fā)中沒有MVC框架,Java使用數(shù)據(jù)庫也比

11、PHP復(fù)雜一些,同時在應(yīng)用中要使用SQLite必須用代碼生成數(shù)據(jù)庫以及數(shù)據(jù)庫表,而不能像服務(wù)端那樣一開始就配置好數(shù)據(jù)庫以及各種表。所以使用SQLite數(shù)據(jù)庫雖然不能說難,但是絕對有些復(fù)雜,以下介紹一般情況下怎么使用SQLite數(shù)據(jù)庫。2.2SQLite操作2.2.1SQLite實例以下是一段已經(jīng)寫好的Activity的onCreate中的操作SQLite的代碼實例(本代碼實例截取于網(wǎng)上,親測有效):38.     Override  39.     protected void

12、0;onCreate(Bundle savedInstanceState)   40.         super.onCreate(savedInstanceState);  41.           42.         /打開或創(chuàng)建test.db數(shù)據(jù)庫 

13、60;43.         SQLiteDatabase db = openOrCreateDatabase("test.db", Context.MODE_PRIVATE, null);  44.         db.execSQL("DROP TABLE IF EXISTS person&q

14、uot;);  45.         /創(chuàng)建person表  46.         db.execSQL("CREATE TABLE person (_id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, age SMALLI

15、NT)");  47.         Person person = new Person();  48.          = "john"  49.         person.a

16、ge = 30;  50.         /插入數(shù)據(jù)  51.         db.execSQL("INSERT INTO person VALUES (NULL, ?, ?)", new O, person.age); 

17、 52.           53.          = "david"  54.         person.age = 33;  55.      &

18、#160;  /ContentValues以鍵值對的形式存放數(shù)據(jù)  56.         ContentValues cv = new ContentValues();  57.         cv.put("name", );  58.   

19、      cv.put("age", person.age);  59.         /插入ContentValues中的數(shù)據(jù)  60.         db.insert("person", null, cv);  61.  

20、60;        62.         cv = new ContentValues();  63.         cv.put("age", 35);  64.        &#

21、160;/更新數(shù)據(jù)  65.         db.update("person", cv, "name = ?", new String"john");  66.           67.      

22、60;  Cursor c = db.rawQuery("SELECT * FROM person WHERE age >= ?", new String"33");  68.         while (c.moveToNext()   69.   

23、          int _id = c.getInt(c.getColumnIndex("_id");  70.             String name = c.getString(c.getColumnIndex("name"); &#

24、160;71.             int age = c.getInt(c.getColumnIndex("age");  72.             Log.i("db", "_id=>" + _id&

25、#160;+ ", name=>" + name + ", age=>" + age);  73.           74.         c.close();  75.      &

26、#160;    76.         /刪除數(shù)據(jù)  77.         db.delete("person", "age < ?", new String"35");  78.      

27、;     79.         /關(guān)閉當(dāng)前數(shù)據(jù)庫  80.         db.close();  81.           82.         /刪除tes

28、t.db數(shù)據(jù)庫  83. /      deleteDatabase("test.db");  84.       2.2.2數(shù)據(jù)庫生成SQLite與服務(wù)端的SQL不同在于需要通過代碼生成數(shù)據(jù)庫,生成數(shù)據(jù)庫的代碼為SQLiteDatabase db = openOrCreateDatabase("test.db", Context.MODE_PRIVATE,

29、 null);  在執(zhí)行完上面的代碼后,系統(tǒng)就會在/data/data/PACKAGE_NAME/databases目錄下生成一個“test.db”的數(shù)據(jù)庫文件,如圖2所示:圖2:SQLite數(shù)據(jù)庫位置這時候數(shù)據(jù)庫里沒有數(shù)據(jù)庫表,通過以下代碼會生成數(shù)據(jù)表persondb.execSQL("CREATE TABLE person (_id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, age SMALLINT)");這樣數(shù)據(jù)庫就生成了。2.2.3操作方法數(shù)據(jù)庫建立好后就應(yīng)該進(jìn)行增刪改查等操作了,

30、實例中的代碼中基本上囊括了大部分的數(shù)據(jù)庫操作;對于添加、更新和刪除來說,我們都可以使用。相似于PHP中的query()語句,SQLite使用executeSQL()來執(zhí)行sql語句,如下:1. db.executeSQL(String sql);  2. db.executeSQL(String sql, Object bindArgs);/sql語句中使用占位符,然后第二個參數(shù)是實際的參數(shù)集  增刪改語句如下:3. db.insert(String table, String nul

31、lColumnHack, ContentValues values);  4. db.update(String table, Contentvalues values, String whereClause, String whereArgs);  5. db.delete(String table, String whereClause, String whereArgs);  以上三個方法的

32、第一個參數(shù)都是表示要操作的表名;insert中的第二個參數(shù)表示如果插入的數(shù)據(jù)每一列都為空的話,需要指定此行中某一列的名稱,系統(tǒng)將此列設(shè)置為NULL,不至于出現(xiàn)錯誤;insert中的第三個參數(shù)是ContentValues類型的變量,是鍵值對組成的Map,key代表列名,value代表該列要插入的值;update的第二個參數(shù)也很類似,只不過它是更新該字段key為最新的value值,第三個參數(shù)whereClause表示W(wǎng)HERE表達(dá)式,比如“age > ? and age < ?”等,最后的whereArgs參數(shù)是占位符的實際參數(shù)值;delete方法的參數(shù)也是一樣。下面來說說查詢操作。查

33、詢操作相對于上面的幾種操作要復(fù)雜些,因為我們經(jīng)常要面對著各種各樣的查詢條件,所以系統(tǒng)也考慮到這種復(fù)雜性,為我們提供了較為豐富的查詢形式:6. db.rawQuery(String sql, String selectionArgs);  7. db.query(String table, String columns, String selection, String selectionArgs, String groupBy, String&#

34、160;having, String orderBy);  8. db.query(String table, String columns, String selection, String selectionArgs, String groupBy, String having, String orderBy, String limit);  9. db.query(String&#

35、160;distinct, String table, String columns, String selection, String selectionArgs, String groupBy, String having, String orderBy, String limit);  上面幾種都是常用的查詢方法,第一種最為簡單,將所有的SQL語句都組織到一個字符串中,使用占位符代替實際參數(shù),selection

36、Args就是占位符實際參數(shù)集;下面的幾種參數(shù)都很類似,columns表示要查詢的列所有名稱集,selection表示W(wǎng)HERE之后的條件語句,可以使用占位符,groupBy指定分組的列名,having指定分組條件,配合groupBy使用,orderBy指定排序的列名,limit指定分頁參數(shù),distinct可以指定“true”或“false”表示要不要過濾重復(fù)值。需要注意的是,selection、groupBy、having、orderBy、limit這幾個參數(shù)中不包括“WHERE”、“GROUP BY”、“HAVING”、“ORDER BY”、“LIMIT”等SQL關(guān)鍵字。最后,他們同時返回

37、一個Cursor對象,代表數(shù)據(jù)集的游標(biāo),有點類似于JavaSE中的ResultSet。下面是Cursor對象的常用方法: 10. c.move(int offset); /以當(dāng)前位置為參考,移動到指定行  11. c.moveToFirst();    /移動到第一行  12. c.moveToLast();     /移動到最后一行  13. c.moveToPosition(int position); 

38、;/移動到指定行  14. c.moveToPrevious(); /移動到前一行  15. c.moveToNext();     /移動到下一行  16. c.isFirst();        /是否指向第一條  17. c.isLast();     /是否指向最后一條  18. c.isBefore

39、First();  /是否指向第一條之前  19. c.isAfterLast();    /是否指向最后一條之后  20. c.isNull(int columnIndex);  /指定列是否為空(列基數(shù)為0)  21. c.isClosed();       /游標(biāo)是否已關(guān)閉  22. c.getCount();   

40、60;   /總數(shù)據(jù)項數(shù)  23. c.getPosition();    /返回當(dāng)前游標(biāo)所指向的行數(shù)  24. c.getColumnIndex(String columnName);/返回某列名對應(yīng)的列索引值  25. c.getString(int columnIndex);   /返回當(dāng)前行指定列的值  在上面的代碼示例中,已經(jīng)用到了這幾個常用方法中的一些,關(guān)于更多的信息,大家可以參考官方

41、文檔中的說明。2.3對現(xiàn)有SQLite 框架評價通過以上實例我們基本了解了SQLite的基本使用,現(xiàn)在網(wǎng)上也流傳有一些封裝好的SQLite框架,我找了一個比較好的,如下所示:26. package com.scott.db;  27.   28. import java.util.ArrayList;  29. import java.util.List;  30.   31. import android.content.ContentValues;&#

42、160; 32. import android.content.Context;  33. import android.database.Cursor;  34. import android.database.sqlite.SQLiteDatabase;  35.   36. public class DBManager   37.     private DBHelper

43、 helper;  38.     private SQLiteDatabase db;  39.       40.     public DBManager(Context context)   41.         helper = 

44、;new DBHelper(context);  42.         /因為getWritableDatabase內(nèi)部調(diào)用了mContext.openOrCreateDatabase(mName, 0, mFactory);  43.         /所以要確保context已初始化,我們可以把實例化DBManager的步驟放在Activity的onCreate

45、里  44.         db = helper.getWritableDatabase();  45.       46.       47.     /* 48.      * add persons 

46、49.      * param persons 50.      */  51.     public void add(List<Person> persons)   52.         db.beginTransaction(); 

47、60;/開始事務(wù)  53.         try   54.             for (Person person : persons)   55.           

48、      db.execSQL("INSERT INTO person VALUES(null, ?, ?, ?)", new O, person.age, );  56.               5

49、7.             db.setTransactionSuccessful();  /設(shè)置事務(wù)成功完成  58.          finally   59.             db.

50、endTransaction();    /結(jié)束事務(wù)  60.           61.       62.       63.     /* 64.      * update person

51、9;s age 65.      * param person 66.      */  67.     public void updateAge(Person person)   68.         ContentValues cv

52、 = new ContentValues();  69.         cv.put("age", person.age);  70.         db.update("person", cv, "name = ?", new Str

53、);  71.       72.       73.     /* 74.      * delete old person 75.      * param person 76.   &#

54、160;  */  77.     public void deleteOldPerson(Person person)   78.         db.delete("person", "age >= ?", new StringString.valueOf(person.age

55、);  79.       80.       81.     /* 82.      * query all persons, return list 83.      * return List<Person>&#

56、160;84.      */  85.     public List<Person> query()   86.         ArrayList<Person> persons = new ArrayList<Person>();  87.  &

57、#160;      Cursor c = queryTheCursor();  88.         while (c.moveToNext()   89.             Person person = n

58、ew Person();  90.             person._id = c.getInt(c.getColumnIndex("_id");  91.              = c.getString(c.get

59、ColumnIndex("name");  92.             person.age = c.getInt(c.getColumnIndex("age");  93.              = c.ge

60、tString(c.getColumnIndex("info");  94.             persons.add(person);  95.           96.         c.close();  

61、;97.         return persons;  98.       99.       100.     /* 101.      * query all persons, return cursor

62、0;102.      * return  Cursor 103.      */  104.     public Cursor queryTheCursor()   105.         Cursor c = db.rawQuery

63、("SELECT * FROM person", null);  106.         return c;  107.       108.       109.     /* 110.     

64、 * close database 111.      */  112.     public void closeDB()   113.         db.close();  114.       115.   以

65、上這個數(shù)據(jù)庫類明顯只能操作person表,并不像ThinkPHP那樣為每個表生成一個表類并直接操作表類針對特定的表進(jìn)行操作,缺陷眾多,本人尋找許久都未曾找到類似ThinkPHP的SQLite數(shù)據(jù)庫類框架,所以下面會介紹一個本人自己編寫的SQLite數(shù)據(jù)庫類框架。3自編SQLite數(shù)據(jù)庫類框架這里要介紹的SQLite數(shù)據(jù)庫框架為本人自己編寫,其配置方法與ThinkPHP的略有不同,但是卻具備了部分MVC結(jié)構(gòu)的用法,使用原理是一樣的。3.1框架結(jié)構(gòu)圖3是框架的結(jié)構(gòu):圖3:自編SQLite數(shù)據(jù)庫類框架結(jié)構(gòu)圖com.example.dbserver包是數(shù)據(jù)庫服務(wù)包。com.example.tables

66、是數(shù)據(jù)表類的存放包。com.example.sqliteframework是主程序包,會Android的同學(xué)應(yīng)該知道。下面要分別介紹com.example.dbserver包和com.example.tables包內(nèi)的文件。3.1.1com.example.dbserver包MyDbHelper.java文件是SQLite數(shù)據(jù)庫的連接和定義基礎(chǔ)方法的類,代碼如下所示:116. package com.example.dbserver;117.118. import android.content.ContentValues;119. import android.content.Context

67、;120. import android.database.Cursor;121. import android.database.SQLException;122. import android.database.sqlite.SQLiteDatabase;123. import android.database.sqlite.SQLiteOpenHelper;124.125. public class MyDbHelper126. 127. private DatabaseHelper mDbHelper; 128. private SQLiteDatabase mDb; 129. pri

68、vate static MyDbHelper openHelper = null;130. 131. private static int version = 1;132. 133. private static String myDBName = "mydb"134. private static String TableNames;135. private static String FieldNames;136. private static String FieldTypes;137. private static String NO_CREATE_TABLES =

69、 "no tables"138. private static String message = ""139. 140. private final Context mCtx; 141. 142. private MyDbHelper(Context ctx) 143. this.mCtx = ctx;144. 145. /構(gòu)造類導(dǎo)入表參數(shù)和創(chuàng)建數(shù)據(jù)庫和數(shù)據(jù)庫表146. public static MyDbHelper getInstance(Context context)147. if(openHelper = null)148. openHelpe

70、r = new MyDbHelper(context);149. TableNames = MyDbInfo.getTableNames();/導(dǎo)入表名150. FieldNames = MyDbInfo.getFieldNames();/導(dǎo)入表字段151. FieldTypes = MyDbInfo.getFieldTypes();/導(dǎo)入字段分類152. 153. return openHelper;154. 155. 156. private static class DatabaseHelper extends SQLiteOpenHelper 157. 158. DatabaseHel

71、per(Context context) 159. super(context, myDBName, null, version);160. 161. Override/助手創(chuàng)建162. public void onCreate(SQLiteDatabase db)163. 164. if (TableNames = null)165. 166. message = NO_CREATE_TABLES;167. return;168. 169. for (int i = 0; i < TableNames.length; i+)170. 171. String sql = "CR

72、EATE TABLE " + TableNamesi + " ("172. for (int j = 0; j < FieldNamesi.length; j+)173. 174. sql += FieldNamesij + " " + FieldTypesij + ","175. 176. sql = sql.substring(0, sql.length() - 1);177. sql += ")"178. db.execSQL(sql);179. 180. 181. /注銷182. Overr

73、ide183. public void onUpgrade(SQLiteDatabase db, int arg1, int arg2)184. 185. for (int i = 0; i < TableNamesi.length(); i+)186. 187. String sql = "DROP TABLE IF EXISTS " + TableNamesi;188. db.execSQL(sql);189. 190. onCreate(db);191. 192. 193. 194. /插入表195. public void insertTables(Strin

74、g tableNames,String fieldNames,String fieldTypes)196. TableNames = tableNames;197. FieldNames = fieldNames;198. FieldTypes = fieldTypes;199. 200. 201. /打開數(shù)據(jù)庫202. public MyDbHelper open() throws SQLException 203. mDbHelper = new DatabaseHelper(mCtx);204. mDb = mDbHelper.getWritableDatabase();205. ret

75、urn this;206. 207. 208. /關(guān)閉數(shù)據(jù)庫209. public void close() 210. mDbHelper.close();211. 212. /query語句定義213. public void execSQL(String sql) throws java.sql.SQLException214. 215. mDb.execSQL(sql);216. 217. 218. 219. public Cursor rawQuery(String sql,String selectionArgs)220. 221. Cursor cursor = mDb.rawQu

76、ery(sql, selectionArgs);222. return cursor;223. 224. 225. /查詢方法定義226. public Cursor select(String table, String columns, 227. String selection, String selectionArgs, String groupBy, 228. String having, String orderBy)229. 230. Cursor cursor = mDb.query231. (232. table, columns, selection, selectionA

77、rgs, 233. groupBy, having, orderBy234. );235. return cursor;236. 237. 238. /插入方法定義239. public long insert(String table, String fields, String values)240. 241. ContentValues cv = new ContentValues();242. for (int i = 0; i < fields.length; i+)243. 244. cv.put(fieldsi, valuesi);245. 246. return mDb.

78、insert(table, null, cv);247. 248. 249. /刪除方法定義250. public int delete(String table, String where, String whereValue)251. 252. return mDb.delete(table, where, whereValue);253. 254. 255. 256. public int update(String table, String updateFields,257. String updateValues, String where, String whereValue)2

79、58. 259. ContentValues cv = new ContentValues();260. for (int i = 0; i < updateFields.length; i+)261. 262. cv.put(updateFieldsi, updateValuesi);263. 264. return mDb.update(table, cv, where, whereValue);265. 266. 267. 268. public String getMessage()269. 270. return message;271. 272. 273. 274. 以上的代

80、碼已經(jīng)將定義了數(shù)據(jù)庫操作的基本方法和連接數(shù)據(jù)。下面的MyDbInfo.java里存放數(shù)據(jù)庫的各種表的信息,供MyDbHelper.java在構(gòu)造函數(shù)中調(diào)用并生成數(shù)據(jù)庫文件,代碼如下所示:275. package com.example.dbserver;276.277. public class MyDbInfo 278. /定義表名279. private static String TableNames = 280. "TBL_USER_INFO",281. "TBL_EXPENDITURE_CATEGORY",282. "TBL_EXPE

81、NDITURE_SUB_CATEGORY",283. "TBL_INCOME_CATEGORY",284. "TBL_INCOME_SUB_CATEGORY",285. "TBL_ACCOUNT_TYPE",286. "TBL_ACCOUNT_SUB_TYPE",287. "TBL_ACCOUNT",288. "TBL_STORE",289. "TBL_ITEM",290. "TBL_EXPENDITURE",291. &qu

82、ot;TBL_INCOME",292. "TBL_TRANSFER"293. ;294. /定義各個表的字段295.296. private static String FieldNames = 297. "ID","NAME","AGE",298. "ID","NAME","BUDGET",299. "ID","NAME","PARENT_CATEGORY_ID",300. "ID","NAME",301. "ID","NAME","PARENT_CATEGORY_ID&quo

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論