Chinaunix首页 | 论坛 | 博客
  • 博客访问: 36442
  • 博文数量: 25
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 270
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-28 17:38
文章分类
文章存档

2013年(25)

我的朋友

分类: Android平台

2013-04-18 16:36:09

Android---把数据保存到数据库中
 
把数据放入数据库
 
通过把ContentValues对象传入instert()方法把数据插入数据库:
 
// Gets the data repository in write mode 
SQLiteDatabase db = mDbHelper.getWritableDatabase(); 
 
// Create a new map of values, where column names are the keys 
ContentValues values = new ContentValues(); 
values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_ENTRY_ID, id); 
values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_TITLE, title); 
values.put(FeedReaderContract.FeedEntry.COLUMN_NAME_CONTENT, content); 
 
// Insert the new row, returning the primary key value of the new row 
long newRowId; 
newRowId = db.insert( 
         FeedReaderContract.FeedEntry.TABLE_NAME, 
         FeedReaderContract.FeedEntry.COLUMN_NAME_NULLABLE, 
         values);
 
insert()方法的第一个参数是表名。第二个参数提供了框架中的一个列名,在ContentValues的值是空的时候,框架会向表中插入NULL值(如果这个参数是“null”,那么当没有值时,框架不会向表中插入一行。
阅读(349) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

wancl1582013-04-22 15:04:40

www.ccrr188.com全讯网
www.ccrr188.com全讯2