码迷,mamicode.com
首页 > 移动开发 > 详细

Android中的ContentValues用法

时间:2014-07-01 18:19:28      阅读:258      评论:0      收藏:0      [点我收藏+]

标签:android   数据   代码   数据库   sql   new   

ContentValues 和HashTable类似都是一种存储的机制 但是两者最大的区别就在于,contenvalues只能存储基本类型的数据,像string,int之类的,不能存储对象这种东西,而HashTable却可以存储对象。ContentValues存储对象的时候,以(key,value)的形式来存储数据。

在忘数据库中插入数据的时候,首先应该有一个ContentValues的对象所以:

ContentValues initial = new ContentValues();

initial.put(key,values);

SQLiteDataBase db ;

db.insert(database_name,null,initialValues);

插入成功就返回记录的id否则返回-1;

示例代码:一个简单的插入
public long insert(String text)
{
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.put(FIELD_TEXT, text);
    long row = db.insert(TABLE_NAME, null, cv);
    return row;
}

Android中的ContentValues用法,布布扣,bubuko.com

Android中的ContentValues用法

标签:android   数据   代码   数据库   sql   new   

原文地址:http://www.cnblogs.com/ahao214/p/3817719.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!