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和不改变用户 ...
随机推荐
- shell的简单介绍
一 什么叫shell,shell 是什么 如果考虑到操作系统其实是一组软件,我们可以发现应用程序其实是在最外层,就如同鸡蛋的外壳一样,因此这个也就被称为shell. 其实shell的功能只是提供用户操 ...
- LOJ#2244. 「NOI2014」起床困难综合症
$n \leq 1e5$个位运算操作,$m \le 2^{30}$,问$0-m$中谁进行完所有操作值最大,输出这个最大值. cfA题难度?当送分题就不管了 and相当于几个位取0,or相当于几个位取1 ...
- Javascript&Ajax-深入浅出JSONP--解决ajax跨域问题
Javascript&Ajax-深入浅出JSONP--解决ajax跨域问题 原理讲解: 链接地址:http://www.cnblogs.com/chopper/archive/2012/03/ ...
- Sql常用日期格式
原文发布时间为:2010-09-16 -- 来源于本人的百度文章 [由搬家工具导入] SQL Server中文版的默认的日期字段datetime格式是yyyy-mm-dd Thh:mm:ss.mmm ...
- VBCodeProvider .net compiler service interface or something like that
https://msdn.microsoft.com/zh-cn/library/microsoft.visualbasic.vbcodeprovider%28v=vs.110%29.aspx ref ...
- configurationmanager.getsection usage example.
1.app.config(note that attribute case sensitive!) <?xml version="1.0" encoding="ut ...
- 学习总结——Postman做http接口功能测试
Postman做各种类型的http接口测试 首先,做接口测试前要有明确的接口文档(e.g. http://test.nnzhp.cn/wiki/index.php?doc-view-59) ,假设已经 ...
- 已知一个序列A1.A2….An,给你一个整数K,找到满足所有Ai+Aj>=k的数对(i,j)的个数
#include<bits/stdc++.h> using namespace std; #define ll long long #define maxn 100010 /* 已知一个序 ...
- 利用Django徒手写个静态页面生成工具
每个Geek对折腾自己的博客都有着一份执念 背景介绍 曾经多次在不同的平台写博客,但全部都以失败而告终.去年七月选择微信公众号做为平台开始了又一次的技术分享,庆幸一直坚持到现在,但随着文章发表的越来越 ...
- dhlin-vim-wiki
记录vim中常用的几个操作 入门指南 $ vimtutor vim中是区分大小写 vim中移动光标 h 向左移动 j 向下移动 k 向上移动 l 向右移动 其实使用方向键也是能移动的,但是熟悉后再一些 ...