如何在SQLite中插入名称,联系人,图像等记录?

时间:2016-04-07 06:24:38

标签: android sqlite

public class MyDataBase extends SQLiteOpenHelper {
    public MyDataBase(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("create table tableregimage(int userid number autoincrement,username text,useraddress text,usercontact text,image blob);");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

1 个答案:

答案 0 :(得分:1)

此方法可帮助您插入记录:

 void addContact(String Name,String Contact,String Image) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_NAME, Name ); 
    values.put(KEY_CONTACT, Contact);
    values.put(KEY_IMAGE, Image)

    // Inserting Row
    db.insert(TABLE_CName, null, values);
    db.close(); // Closing database connection
}