Android · SQLiteOpenHelper实例PrivateContactsDBHelper
package privatecontact; import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; public class PrivateContactsDBHelper extends SQLiteOpenHelper { public static final String DATABASE_NAME = "pContacts.db";
public static final int DATABASE_VERSION = 1;
public static final String TABLE_NAME = "pcontacts";
public final static String ID = "_id";
public final static String NAME = "name";
public final static String MOBILE = "mobile";
public final static String EMAIL ="email"; public PrivateContactsDBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
} @Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE " + TABLE_NAME + " (" + ID
+ " INTEGER primary key autoincrement, " + NAME
+ " text, " + MOBILE + " text, " + EMAIL + " text);";
db.execSQL(sql);
} @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
} public Cursor select() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db
.query(TABLE_NAME, null, null, null, null, null, null);
return cursor;
} public long insert(String arg1, String arg2, String arg3) {
SQLiteDatabase db = this.getWritableDatabase();
/* ContentValues */
ContentValues cv = new ContentValues();
cv.put(NAME, arg1);
cv.put(MOBILE, arg2);
cv.put(EMAIL, arg3);
long row = db.insert(TABLE_NAME, null, cv);
return row;
} public void delete(int id) {
SQLiteDatabase db = this.getWritableDatabase();
String where = ID + " = ?";
String[] whereValue = { Integer.toString(id) };
db.delete(TABLE_NAME, where, whereValue);
} public void update(int id, String arg1, String arg2, String arg3) {
SQLiteDatabase db = this.getWritableDatabase();
String where = ID + " = ?";
String[] whereValue = { Integer.toString(id) }; ContentValues cv = new ContentValues();
cv.put(NAME, arg1);
cv.put(MOBILE, arg2);
cv.put(EMAIL, arg3);
db.update(TABLE_NAME, cv, where, whereValue);
} }
Android · SQLiteOpenHelper实例PrivateContactsDBHelper的更多相关文章
- android本地数据库,微信数据库WCDB for Android 使用实例
android本地数据库,微信数据库WCDB for Android 使用实例 Home · Tencent/wcdb Wikihttps://github.com/Tencent/wcdb/wiki ...
- 【Android 开发实例】时间管理APP开发之数据库设计
当然也能够先写界面什么的.可是,总认为先把数据库后台写好在写界面比較放心. 对于数据库的设计,我一開始没什么概念.甚至不知道怎样下手,一開始想着设计成几个表?有哪些字段? 最后用了两天时间,还是一无所 ...
- Android HTTP实例 使用GET方法和POST方法发送请求
Android HTTP实例 使用GET方法和POST方法发送请求 Web程序:使用GET和POST方法发送请求 首先利用MyEclispe+Tomcat写好一个Web程序,实现的功能就是提交用户信息 ...
- Android HTTP实例 发送请求和接收响应
Android HTTP实例 发送请求和接收响应 Android Http连接 实例:发送请求和接收响应 添加权限 首先要在manifest中加上访问网络的权限: <manifest ... & ...
- Android图像处理实例教程
Android图像处理实例教程 原始出处 http://vaero.blog.51cto.com/4350852/856750
- Android SQLiteOpenHelper(二)
上一篇我们已经了解了SQLiteOpenHelper 和 构造函数. 现在我们就来掌握一下:onCreate( ) onUpgrade( ) onDowngrade( ) public void ...
- Android SQLiteOpenHelper(一)
SQLiteOpenHelper api解释: A helper class to manage database creation and version management. You creat ...
- 一个简单的Android小实例
原文:一个简单的Android小实例 一.配置环境 1.下载intellij idea15 2.安装Android SDK,通过Android SDK管理器安装或卸载Android平台 3.安装J ...
- 【转】 Android常用实例—Alert Dialog的使用
Android常用实例—Alert Dialog的使用 AlertDialog的使用很普遍,在应用中当你想要用户做出“是”或“否”或者其它各式各样的选择时,为了保持在同样的Activity和不改变用户 ...
随机推荐
- /bin , /sbin , /usr/sbin , /usr/local/sbin 的区别
usr 是 UNIX Software Resource 的缩写,也就是 Unix操作系统软件资源 所放置的目录. 一 /bin:Essential user command binaries(for ...
- Eclipse SVN冲突详细解决方案
大家一起开发,难免有时会同时修改同一个文件,这样就要学会解决冲突.当大家更新代码,发现以下情况的时候,就说明你的修改的文件和服务器的文件产生了冲突(一般是别人也改了同一个文件). 1)和服务 ...
- T-SQL获取同类型数据不足补全的方法
业务规则:如果有本地区的招聘会,显示本地区,如果没有本地区的招聘会,显示最近一场. 一条SQL搞定: [userId],[meetsName],[provinceId], [province],[ci ...
- 【HDOJ5534】Partial Tree(树,背包DP)
题意:有一棵n个点的形态不定的树,每个度为i的节点会使树的权值增加f[i],求树的最大权值 n<=2015,0<=f[i]<=1e4 思路:对不起队友,我再强一点就能赛中出这题了 显 ...
- token in c and cpp (C preprocessor)
C tokens are of six types, They are, keyword identifier constant string-literal punctuator preproces ...
- hdu 1576(逆元)
A/B Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- malloc和free函数的使用
#include <stdio.h> #include <stdlib.h> int main() { int *p,t; p = (int *)malloc(40*sizeo ...
- sprintf 心得
[string print format]sprintf指的是字符串格式化命令. [主要功能]是把格式化的数据写入某个字符串中. sprintf是个变参函数. 使用sprintf对于写入buffer的 ...
- Azure CDN 服务详解
Azure CDN概述 Azure CDN(内容分发网络)是一种用于分发高带宽内容的全球CDN解决方案,它可以托管在Azure中,也可以通过在任何其他位置,借助Azure CDN,可以托管到任何其 ...
- MyBatis一级缓存(转载)
<深入理解mybatis原理> MyBatis的一级缓存实现详解 及使用注意事项 http://demo.netfoucs.com/luanlouis/article/details/41 ...