【Android源码 栏目提醒】:网学会员为需要Android源码 的朋友们搜集整理了Android自定义数据库源码 - 培训教程相关资料,希望对各位网友有所帮助!
import android.content.ContentValues import android.content.Context import android.database.Cursor import android.database.sqlite.SQLiteDatabase import android.database.sqlite.SQLiteOpenHelper public class array extends SQLiteOpenHelper private final static String DATABASE_NAME todo_db private final static int DATABASE_VERSION 1 private final static String TABLE_NAME todo_table public final static String FIELD_id _id public final static String FIELD_TEXT todo_text public arrayContext context supercontext DATABASE_NAME null DATABASE_VERSION Override public void onCreateSQLiteDatabase db // ??¨????table String sql CREATE TABLE TABLE_NAME FIELD_id INTEGER primary key autoincrement FIELD_TEXT text db.execSQLsql Override public void onUpgradeSQLiteDatabase db int oldVersion int newVersion String sql DROP TABLE IF EXISTS TABLE_NAME db.execSQLsql onCreatedb public Cursor select SQLiteDatabase db this.getReadableDatabase Cursor cursor db.queryTABLE_NAME null null null null null null return cursor public long insertString text SQLiteDatabase db this.getWritableDatabase // ????????????????????·??????ContentValues ContentValues cv new ContentValues cv.putFIELD_TEXT text long row db.insertTABLE_NAME null cv return row public void deleteint id SQLiteDatabase db this.getWritableDatabase String where FIELD_id String whereValue Integer.toStringid db.deleteTABLE_NAME where whereValue public void updateint id String text SQLiteDatabase db this.getWritableDatabase String where FIELD_id String whereValue Integer.toStringid // ????????????????????·??????ContentValues ContentValues cv new ContentValues cv.putFIELD_TEXT text db.updateTABLE_NAME cv where whereValue