Android SqlLiter使用
来源:互联网 发布:武汉大数据培训班 编辑:程序博客网 时间:2024/05/19 02:17
package com.jl;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
public class dbHelper extends SQLiteOpenHelper {
private final static String DATABASE_NAME="sec_db";
private final static int DATABASE_VERSION=1;
private final static String TABLE_NAME="sec_pwd";
public final static String FIELD_ID="_id";
public final static String FIELD_TITLE="sec_Title";
public dbHelper(Context context)
{
super(context, DATABASE_NAME,null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String sql="Create table "+TABLE_NAME+"("+FIELD_ID+" integer primary key autoincrement,"
+FIELD_TITLE+" text );";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
String sql=" DROP TABLE IF EXISTS "+TABLE_NAME;
db.execSQL(sql);
onCreate(db);
}
public long insert(String Title)
{
SQLiteDatabase db=this.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(FIELD_TITLE, Title);
long row=db.insert(TABLE_NAME, null, cv);
return row;
}
{
SQLiteDatabase db=this.getWritableDatabase();
String where=FIELD_ID+"=?";
String[] whereValue={Integer.toString(id)};
db.delete(TABLE_NAME, where, whereValue);
}
{
SQLiteDatabase db=this.getWritableDatabase();
String where=FIELD_ID+"=?";
String[] whereValue={Integer.toString(id)};
ContentValues cv=new ContentValues();
cv.put(FIELD_TITLE, Title);
db.update(TABLE_NAME, cv, where, whereValue);
}
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
public class dbHelper extends SQLiteOpenHelper {
private final static String DATABASE_NAME="sec_db";
private final static int DATABASE_VERSION=1;
private final static String TABLE_NAME="sec_pwd";
public final static String FIELD_ID="_id";
public final static String FIELD_TITLE="sec_Title";
public dbHelper(Context context)
{
super(context, DATABASE_NAME,null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String sql="Create table "+TABLE_NAME+"("+FIELD_ID+" integer primary key autoincrement,"
+FIELD_TITLE+" text );";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
String sql=" DROP TABLE IF EXISTS "+TABLE_NAME;
db.execSQL(sql);
onCreate(db);
}
public long insert(String Title)
{
SQLiteDatabase db=this.getWritableDatabase();
ContentValues cv=new ContentValues();
cv.put(FIELD_TITLE, Title);
long row=db.insert(TABLE_NAME, null, cv);
return row;
}
/*执行删除,调用db的delete,需要三个参数*/
public void delete(int id){
SQLiteDatabase db=this.getWritableDatabase();
String where=FIELD_ID+"=?";
String[] whereValue={Integer.toString(id)};
db.delete(TABLE_NAME, where, whereValue);
}
/*跟新表数据,执行update,需要四个参数*/
/*传入参数为限制条件,和更新后的值*/
public void update(int id,String Title){
SQLiteDatabase db=this.getWritableDatabase();
String where=FIELD_ID+"=?";
String[] whereValue={Integer.toString(id)};
ContentValues cv=new ContentValues();
cv.put(FIELD_TITLE, Title);
db.update(TABLE_NAME, cv, where, whereValue);
}
/*查找,结果按id排序降序*/
public Cursor select()
{
SQLiteDatabase db=this.getReadableDatabase();
Cursor cursor=db.query(TABLE_NAME, null, null, null, null, null, " _id desc");
return cursor;
}
}
from:http://www.cnblogs.com/TerryBlog/archive/2010/06/12/1757166.html
- Android SqlLiter使用
- Android使用
- Android使用
- Android使用
- 【android】 android studio使用
- android使用keytools使用
- 【Android】Android LogCat使用详解
- 【Android】Android LogCat使用详解
- Android:Android Fragments 详细使用
- android布局 android:Theme使用
- #android#android studio 使用cardview
- 【android】:android之使用Intent
- 【Android】Android对话框的使用
- 【Android】android Fragment的使用
- 【Android】Android SurfaceView使用详解
- Android进阶---android databinding 使用
- android:Android中pullToRefresh使用
- Android WebView使用【初级使用】
- oradebug命令 简介
- First。
- 第三章续、Top K算法问题的实现
- Android HTTP请求访问的方法
- 寻找最小的k个数
- Android SqlLiter使用
- java基础笔记
- DataTable 的用法
- 成员函数、虚函数、this指针
- 乐趣是什么--《全景探秘游戏设计艺术》笔记
- dip,dpi,sp,density官方解答
- 为什么SqlMapClientFactoryBean与SqlMapClient类型不同也可被注入
- 1.4、单例模式
- iOS5新特性:Core Image 图片处理的强力框架