android sqlite自定义DBHelper
[java]package com.sms.db;import java.io.BufferedReader;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.HashMap;import com.sms.util.SmSEntity;import android.content.ContentValues;import android.content.Context;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteOpenHelper;import android.os.Environment;import android.os.Handler;import android.os.Message;public class DBHelper {public static final String DB_DBNAME="sms_db";public static final String DB_TABLENAME="sms_content";public static final int VERSION = 1;public static SQLiteDatabase dbInstance;private MyDBHelper myDBHelper;private StringBuffer tableCreate;private Context context;public DBHelper(Context context) {this.context = context;}public void openDatabase() {if(dbInstance == null) {myDBHelper = new MyDBHelper(context,DB_DBNAME,VERSION);dbInstance = myDBHelper.getWritableDatabase();}}/**** @param user* @return*/public long insert(SmSEntity smsEntity){ContentValues values = new ContentValues();// values.put("id", smsEntity.getId());values.put("content", smsEntity.getContent());values.put("chatTime", smsEntity.getChatTime());values.put("isComeMsg",smsEntity.getTrueO易做图lse());values.put("type", smsEntity.getType());return dbInstance.insert(DB_TABLENAME, null, values);}/**** @param privacy* @return list*/public ArrayList getAllUser(boolean privacy) {ArrayList list = new ArrayList();Cursor cursor = null;if(privacy) {cursor = dbInstance.query(DB_TABLENAME,new String[]{"_id","name","mobilephone","officephone","familyphone","address","othercontact","email","position","company","zipcode","remark","imageid"},"privacy=1",null,null,null,null);} else {cursor = dbInstance.query(DB_TABLENAME,new String[]{"_id","name","mobilephone","officephone","familyphone","address","othercontact","email","position","company","zipcode","remark","imageid"},"privacy=0",null,null,null,null);}while(cursor.moveToNext()) {HashMap item = new HashMap();item.put("_id", cursor.getInt(cursor.getColumnIndex("_id")));item.put("name", cursor.getString(cursor.getColumnIndex("name")));item.put("mobilephone", cursor.getString(cursor.getColumnIndex("mobilephone")));item.put("officephone", cursor.getString(cursor.getColumnIndex("officephone")));item.put("familyphone", cursor.getString(cursor.getColumnIndex("familyphone")));item.put("address", cursor.getString(cursor.getColumnIndex("address")));item.put("othercontact", cursor.getString(cursor.getColumnIndex("othercontact")));item.put("email", cursor.getString(cursor.getColumnIndex("email")));item.put("position", cursor.getString(cursor.getColumnIndex("position")));item.put("company", cursor.getString(curso补充:移动开发 , Android ,
上一个:maven 管理项目实践指南
下一个:Android 获取标题栏的高度
- 更多SQLite疑问解答:
- 数据库sqlite3 里:用函数sqlite3_get_table来获取数据是否 可以 排序么(order by cTime asc)
- 开始学sqlite,在下载了个sqlite3_exe,和一个sqlite admin数据库,我现在疑问的是,可以通过sqlite3.exe
- 关于Sqlite使用Group by以后的排序问题。
- sqlite做网络数据库怎么样
- sqlite支持动态sQL,能不能给个对表名进行拼接的,可以运行通的过的代码范例啊,大侠们
- 用SQLite expert创建的数据库,如何导入到android中
- sqlite3 开始建立数据库时,没有设定主键。怎么去修改
- Android中用SQLite数据库是出现的错误,帮忙解决一下:
- android 应用程序开发用到数据库 ,是否需要使用SQLite Manager
- sqlite查询条件参数为空怎么办
- Android sqlite通过字符串为条件执行删除某一记录的问题
- android 程序碰到问题,很简单的一个程序,从sqlite数据库里面查找数据,点击按钮后获得相应数据
- sqlite数据库中插入数据时出现database is locked!什么原因?我没有设置密码.
- ios移动开发、QT应用开发、ZigBee协议栈、SQlite数据库支持,这些都可以描述成我应用到的技术吗?
- sqlite和mysql有关系吗? 能代替mysql运行织梦程序吗?