SQLiteDatabase的使用
新建DBHeler.JAVA
- package com.hixin.db;
- import java.util.ArrayList;
- import java.util.HashMap;
- import com.hixin.contact.User;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- public class DBHelper extends SQLiteOpenHelper{
- public final static String DB_NAME = "contact";
- public final static int VERSION = 1;
- private static DBHelper instance = null;
- private SQLiteDatabase db;
- //单例模式
- private DBHelper(Context context) {
- super(context,DB_NAME,null,VERSION);
- }
- public static DBHelper getInstance(Context context) {
- if(instance == null) {
- instance = new DBHelper(context);
- }
- return instance;
- }
- private void openDatabase() {
- if(db == null) {
- db = this.getReadableDatabase();
- }
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- // TODO Auto-generated method stub
- StringBuffer tableCreate = new StringBuffer();
- tableCreate.append("create table user (_id integer primary key autoincrement,")
- .append("name text,")
- .append("mobilephone text,")
- .append("familyphone text,")
- .append("officephone text,")
- .append("position text,")
- .append("company text,")
- .append("address text,")
- .append("email text,")
- .append("othercontact text,")
- .append("zipcode text,")
- .append("remark text,")
- .append("imageid int)");
- db.execSQL(tableCreate.toString());
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- // TODO Auto-generated method stub
- String sql = "drop table if exists user";
- db.execSQL(sql);
- onCreate(db);
- }
- public long save(User user) {
- openDatabase();
- ContentValues value = new ContentValues();
- value.put("name", user.username);
- value.put("mobilephone", user.mobilePhone);
- value.put("familyphone", user.familyPhone);
- value.put("officephone", user.officePhone);
- value.put("position", user.position);
- value.put("address", user.address);
- value.put("email", user.email);
- value.put("othercontact", user.otherContact);
- value.put("zipcode", user.zipCode);
- value.put("remark", user.remark);
- value.put("imageid", user.imageId);
- return db.insert("user", null, value);
- }
- public ArrayList getUserList() {
- openDatabase();
- Cursor cursor = db.query("user", null, null, null, null, null, null);
- ArrayList list = new ArrayList();
- while (cursor.moveToNext()) {
- HashMap map = new HashMap();
- map.put("imageid", cursor.getInt(cursor.getColumnIndex("imageid")));
- map.put("name", cursor.getString(cursor.getColumnIndex("name")));
- map.put("mobilephone", cursor.getString(cursor.getColumnIndex("mobilephone")));
- list.add(map);
- }
- return list;
- }
- }
主函数中调用
//save user to database
DBHelper.getInstance(MainActivity.this).save(user);
save()调用openDatabase(),如果数据库不存在,则自动调用数据库的onCreate()
//检索数据库
ArrayList data = DBHelper.getInstance(this).getUserList();
tv_name.setText((CharSequence) ((HashMap) data.get(position)).get("name"));
另外一种版本
- package com.example.healthembed;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- import com.example.healthembed.dummy.BloodPre;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- import android.widget.Toast;
- public class DatabaseHelper extends SQLiteOpenHelper {
- private static final String DB_NAME = "person.db"; //数据库名称
- private static final int version = 1; //数据库版本
- private static DatabaseHelper instance = null;
- private SQLiteDatabase db;
- //单例模式
- public static DatabaseHelper getInstance(Context context) {
- if(instance == null) {
- instance = new DatabaseHelper(context);
- }
- return instance;
- }
- private void openDatabase() {
- if(db == null) {
- db = this.getReadableDatabase();
- }
- }
- public DatabaseHelper(Context context) {
- super(context, DB_NAME, null, version);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- // TODO Auto-generated method stub
- /* StringBuffer tableCreate = new StringBuffer();
- tableCreate.append("create table user (_id integer primary key autoincrement,")
- .append("hp int,")
- .append("lp int)");
- db.execSQL(tableCreate.toString());
- */
- String tableCreate = new String();
- tableCreate="create table user (_id integer primary key autoincrement,name varchar(16),pdate text,hp int,lp int)";
- db.execSQL(tableCreate);
- // Toast.makeText(MyApplication.getContext(), "数据保存成功", Toast.LENGTH_SHORT).show();
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- // TODO Auto-generated method stub
- String sql = "drop table if exists user";
- db.execSQL(sql);
- onCreate(db);
- }
- public long save(BloodPre user) {
- openDatabase();
- ContentValues value = new ContentValues();
- value.put("name", user.name);
- value.put("pdate",user.time);
- value.put("hp", user.highp);
- value.put("lp", user.lowp);
- return db.insert("user", null, value);
- }
- public ArrayList getUserList() {
- openDatabase();
- Cursor cursor = db.query("user", null, null, null, null, null, null);
- ArrayList<Map> list = new ArrayList();
- while (cursor.moveToNext()) {
- HashMap map = new HashMap();
- map.put("name", cursor.getInt(cursor.getColumnIndex("name")));
- map.put("pdate", cursor.getString(cursor.getColumnIndex("pdate")));
- map.put("hp", cursor.getInt(cursor.getColumnIndex("hp")));
- map.put("lp", cursor.getInt(cursor.getColumnIndex("lp")));
- list.add(map);
- }
- return list;
- }
- }
封装性更好的,适合建立多个表!
- package com.example.health.util;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import com.example.health.bp.DatabaseHelper;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteDatabase.CursorFactory;
- import android.database.sqlite.SQLiteOpenHelper;
- /**
- * @author wuzhixin
- * 有if语句的地方添加 else if代码就行
- * 目的在于用一个SQLiteOpenHelper子类创建多个表,并且表之间是独立的,不会一下在创建多个表
- */
- public class GeneralDbHelper extends SQLiteOpenHelper{
- private static final String DB_NAME = "person.db"; //数据库名称
- private static final int version = 1; //数据库版本
- private static GeneralDbHelper instance = null;
- private SQLiteDatabase db;
- private Object bean;
- //单例模式
- public static GeneralDbHelper getInstance(Context context,Object userType) {
- if(instance == null) {
- instance = new GeneralDbHelper(context,userType);
- }
- return instance;
- }
- private void openDatabase() {
- if(db == null) {
- db = this.getReadableDatabase();
- }
- }
- public GeneralDbHelper (Context context,Object userType) {
- super(context, DB_NAME, null, version);
- this.bean = userType;
- }
- /* (non-Javadoc)
- * @see android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite.SQLiteDatabase)
- */
- @Override
- public void onCreate(SQLiteDatabase db) {
- // TODO Auto-generated method stub
- /* StringBuffer tableCreate = new StringBuffer();
- tableCreate.append("create table user (_id integer primary key autoincrement,")
- .append("hp int,")
- .append("lp int)");
- db.execSQL(tableCreate.toString());
- */
- String tableCreate = new String();
- if(bean instanceof User) {
- tableCreate = "CREATE TABLE zhongduanuser (shenfennum varchar(255) primary key,name varchar(64),regtime varchar(255),address varchar(255), birthdate varchar(255))";
- db.execSQL(tableCreate);
- }
- // Toast.makeText(MyApplication.getContext(), "数据保存成功", Toast.LENGTH_SHORT).show();
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- // TODO Auto-generated method stub
- if(bean instanceof User) {
- String sql = "drop table if exists zhongduanuser";
- db.execSQL(sql);
- }
- onCreate(db);
- }
- public long save(Object obj) {
- openDatabase();
- ContentValues value = new ContentValues();
- if(obj instanceof User) {
- /*private String shenfennum;
- private String name;
- private String regtime;
- private String address;
- private String birthdate;*/
- value.put("shenfennum", ((User)obj).getShenfennum());
- value.put("name", ((User)obj).getName());
- value.put("regtime", ((User)obj).getRegtime());
- value.put("address", ((User)obj).getAddress());
- value.put("birthdate", ((User)obj).getBirthdate());
- return db.insert("zhongduanuser", null, value);
- }else{
- return 0;
- }
- }
- public List<?> getBeanList() {
- openDatabase();
- if(bean instanceof User) {
- Cursor cursor = db.query("zhongduanuser", null, null, null, null, null, null);
- List<User> list = new ArrayList<User>();
- while (cursor.moveToNext()) {
- User user = new User();
- user.setShenfennum(cursor.getString(cursor.getColumnIndex("shenfennum")));
- user.setName(cursor.getString(cursor.getColumnIndex("name")));
- user.setRegtime(cursor.getString(cursor.getColumnIndex("regtime")));
- user.setAddress(cursor.getString(cursor.getColumnIndex("address")));
- user.setBirthdate(cursor.getString(cursor.getColumnIndex("birthdate")));
- list.add(user);
- }
- return list;
- }
- else {
- return null;
- }
- }
- }
保存数据:
//创建数据库,保存用户信息到本地
for (User suser : app.userList) {
GeneralDbHelper.getInstance(MyApplication.getContext(), suser).save(suser);
}
使用数据:
User user = new User();
app.userList = GeneralDbHelper.getInstance(MyApplication.getContext(), user).getBeanList();
上面的不能正确使用,下面的这个可以
- package com.example.health.util;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteDatabase.CursorFactory;
- import android.database.sqlite.SQLiteOpenHelper;
- /**
- * @author wuzhixin
- * 有if语句的地方添加 else if代码就行
- * 目的在于用一个SQLiteOpenHelper子类创建多个表,并且表之间是独立的,不会一下在创建多个表
- */
- public class GeneralDbHelper extends SQLiteOpenHelper{
- private static final String DB_NAME = "person.db"; //数据库名称
- private static final int version = 1; //数据库版本
- private static GeneralDbHelper instance = null;
- private SQLiteDatabase db;
- //单例模式
- public static GeneralDbHelper getInstance(Context context) {
- if(instance == null) {
- instance = new GeneralDbHelper(context);
- }
- return instance;
- }
- private void openDatabase() {
- if(db == null) {
- db = this.getReadableDatabase();
- }
- }
- public GeneralDbHelper (Context context) {
- super(context, DB_NAME, null, version);
- }
- /* (non-Javadoc)
- * @see android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite.SQLiteDatabase)
- */
- @Override
- public void onCreate(SQLiteDatabase db) {
- // TODO Auto-generated method stub
- /* StringBuffer tableCreate = new StringBuffer();
- tableCreate.append("create table user (_id integer primary key autoincrement,")
- .append("hp int,")
- .append("lp int)");
- db.execSQL(tableCreate.toString());
- */
- String tableCreate1 = "CREATE TABLE zhongduanuser (shenfennum varchar(255) primary key,name varchar(64),regtime varchar(255),address varchar(255), birthdate varchar(255))";
- db.execSQL(tableCreate1);
- String tableCreate2="create table xueya2 (_id integer primary key autoincrement,userid varchar(255),regdate varchar(64),shousuo int(11),shuzhang int(11),maibo int(11))";
- db.execSQL(tableCreate2);
- // Toast.makeText(MyApplication.getContext(), "数据保存成功", Toast.LENGTH_SHORT).show();
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- // TODO Auto-generated method stub
- String sql1 = "drop table if exists zhongduanuser";
- db.execSQL(sql1);
- String sql2 = "drop table if exists xueya2";
- db.execSQL(sql2);
- onCreate(db);
- }
- public long save(Object obj) {
- openDatabase();
- ContentValues value = new ContentValues();
- if(obj instanceof User) {
- /*private String shenfennum;
- private String name;
- private String regtime;
- private String address;
- private String birthdate;*/
- value.put("shenfennum", ((User)obj).getShenfennum());
- value.put("name", ((User)obj).getName());
- value.put("regtime", ((User)obj).getRegtime());
- value.put("address", ((User)obj).getAddress());
- value.put("birthdate", ((User)obj).getBirthdate());
- return db.insert("zhongduanuser", null, value);
- }else if(obj instanceof BloodPre){
- /*private String userid;
- private String time;
- private int highp;
- private int lowp;
- private int pulse;*/
- value.put("userid", ((BloodPre)obj).getUserid());
- value.put("regdate", ((BloodPre)obj).getTime());
- value.put("shousuo", ((BloodPre)obj).getHighp());
- value.put("shuzhang", ((BloodPre)obj).getLowp());
- value.put("maibo", ((BloodPre)obj).getPulse());
- return db.insert("xueya2", null, value);
- }else{
- return 0;
- }
- }
- public List<?> getBeanList(Object obj) {
- openDatabase();
- if(obj instanceof User) {
- Cursor cursor = db.query("zhongduanuser", null, null, null, null, null, null);
- List<User> list = new ArrayList<User>();
- while (cursor.moveToNext()) {
- User user = new User();
- user.setShenfennum(cursor.getString(cursor.getColumnIndex("shenfennum")));
- user.setName(cursor.getString(cursor.getColumnIndex("name")));
- user.setRegtime(cursor.getString(cursor.getColumnIndex("regtime")));
- user.setAddress(cursor.getString(cursor.getColumnIndex("address")));
- user.setBirthdate(cursor.getString(cursor.getColumnIndex("birthdate")));
- list.add(user);
- }
- return list;
- }else if(obj instanceof BloodPre){
- Cursor cursor = db.query("xueya2", null, null, null, null, null, null);
- List<BloodPre> list = new ArrayList<BloodPre>();
- while (cursor.moveToNext()) {
- BloodPre bloodpre = new BloodPre();
- bloodpre.setUserid(cursor.getString(cursor.getColumnIndex("userid")));
- bloodpre.setTime(cursor.getString(cursor.getColumnIndex("regdate")));
- bloodpre.setHighp(cursor.getInt(cursor.getColumnIndex("shousuo")));
- bloodpre.setLowp(cursor.getInt(cursor.getColumnIndex("shuzhang")));
- bloodpre.setPulse(cursor.getInt(cursor.getColumnIndex("maibo")));
- list.add(bloodpre);
- }
- return list;
- }
- else {
- return null;
- }
- }
- }
更新的版本:
- package com.example.health.util;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import android.content.ContentValues;
- import android.content.Context;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteDatabase.CursorFactory;
- import android.database.sqlite.SQLiteOpenHelper;
- /**
- * @author wuzhixin
- *
- * 目的在于用一个SQLiteOpenHelper子类创建多个表
- */
- public class GeneralDbHelper extends SQLiteOpenHelper{
- private static final String DB_NAME = "person.db"; //数据库名称
- private static final int version = 1; //数据库版本
- private static GeneralDbHelper instance = null;
- private SQLiteDatabase db;
- //单例模式
- public static GeneralDbHelper getInstance(Context context) {
- if(instance == null) {
- instance = new GeneralDbHelper(context);
- }
- return instance;
- }
- private void openDatabase() {
- if(db == null) {
- db = this.getReadableDatabase();
- }
- }
- public GeneralDbHelper (Context context) {
- super(context, DB_NAME, null, version);
- }
- /* (non-Javadoc)
- * @see android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite.SQLiteDatabase)
- */
- @Override
- public void onCreate(SQLiteDatabase db) {
- // TODO Auto-generated method stub
- /* StringBuffer tableCreate = new StringBuffer();
- tableCreate.append("create table user (_id integer primary key autoincrement,")
- .append("hp int,")
- .append("lp int)");
- db.execSQL(tableCreate.toString());
- */
- String tableCreate1 = "CREATE TABLE zhongduanuser (shenfennum varchar(255) primary key,name varchar(64),regtime varchar(255),address varchar(255), birthdate varchar(255))";
- db.execSQL(tableCreate1);
- String tableCreate2="create table xueya2 (_id integer primary key autoincrement,userid varchar(255),regdate varchar(64),shousuo int(11),shuzhang int(11),maibo int(11))";
- db.execSQL(tableCreate2);
- // Toast.makeText(MyApplication.getContext(), "数据保存成功", Toast.LENGTH_SHORT).show();
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- // TODO Auto-generated method stub
- String sql1 = "drop table if exists zhongduanuser";
- db.execSQL(sql1);
- String sql2 = "drop table if exists xueya2";
- db.execSQL(sql2);
- onCreate(db);
- }
- public long save(Object obj) {
- openDatabase();
- ContentValues value = new ContentValues();
- if(obj instanceof User) {
- /*private String shenfennum;
- private String name;
- private String regtime;
- private String address;
- private String birthdate;*/
- value.put("shenfennum", ((User)obj).getShenfennum());
- value.put("name", ((User)obj).getName());
- value.put("regtime", ((User)obj).getRegtime());
- value.put("address", ((User)obj).getAddress());
- value.put("birthdate", ((User)obj).getBirthdate());
- return db.insert("zhongduanuser", null, value);
- }else if(obj instanceof BloodPre){
- /*private String userid;
- private String time;
- private int highp;
- private int lowp;
- private int pulse;*/
- value.put("userid", ((BloodPre)obj).getUserid());
- value.put("regdate", ((BloodPre)obj).getTime());
- value.put("shousuo", ((BloodPre)obj).getHighp());
- value.put("shuzhang", ((BloodPre)obj).getLowp());
- value.put("maibo", ((BloodPre)obj).getPulse());
- return db.insert("xueya2", null, value);
- }else{
- return 0;
- }
- }
- public List<?> getBeanList(Object obj) {
- openDatabase();
- if(obj instanceof User) {
- Cursor cursor = db.query("zhongduanuser", null, null, null, null, null, null);
- List<User> list = new ArrayList<User>();
- while (cursor.moveToNext()) {
- User user = new User();
- user.setShenfennum(cursor.getString(cursor.getColumnIndex("shenfennum")));
- user.setName(cursor.getString(cursor.getColumnIndex("name")));
- user.setRegtime(cursor.getString(cursor.getColumnIndex("regtime")));
- user.setAddress(cursor.getString(cursor.getColumnIndex("address")));
- user.setBirthdate(cursor.getString(cursor.getColumnIndex("birthdate")));
- list.add(user);
- }
- return list;
- }else if(obj instanceof BloodPre){
- Cursor cursor = db.query("xueya2", null, null, null, null, null, null);
- List<BloodPre> list = new ArrayList<BloodPre>();
- while (cursor.moveToNext()) {
- BloodPre bloodpre = new BloodPre();
- bloodpre.setUserid(cursor.getString(cursor.getColumnIndex("userid")));
- bloodpre.setTime(cursor.getString(cursor.getColumnIndex("regdate")));
- bloodpre.setHighp(cursor.getInt(cursor.getColumnIndex("shousuo")));
- bloodpre.setLowp(cursor.getInt(cursor.getColumnIndex("shuzhang")));
- bloodpre.setPulse(cursor.getInt(cursor.getColumnIndex("maibo")));
- list.add(bloodpre);
- }
- return list;
- }
- else {
- return null;
- }
- }
- public List<?> getBeanList(Object obj,String userID) {
- openDatabase();
- if(obj instanceof BloodPre){
- String query = "select regdate,shousuo,shuzhang,maibo from xueya2 where userid = "+userID;
- Cursor cursor = db.query("xueya2", new String[]{"regdate,shousuo,shuzhang,maibo"},"userid=?", new String[]{userID}, null, null, null);
- List<BloodPre> list = new ArrayList<BloodPre>();
- while (cursor.moveToNext()) {
- BloodPre bloodpre = new BloodPre();
- bloodpre.setTime(cursor.getString(cursor.getColumnIndex("regdate")));
- bloodpre.setHighp(cursor.getInt(cursor.getColumnIndex("shousuo")));
- bloodpre.setLowp(cursor.getInt(cursor.getColumnIndex("shuzhang")));
- bloodpre.setPulse(cursor.getInt(cursor.getColumnIndex("maibo")));
- list.add(bloodpre);
- }
- return list;
- }
- else {
- return null;
- }
- }
- }
存数据:
//创建数据库,保存用户信息到本地
for (User suser : app.userList) {
GeneralDbHelper.getInstance(MyApplication.getContext()).save(suser);
}
取数据:
User user = new User();
app.userList = (List<User>) GeneralDbHelper.getInstance(MyApplication.getContext()).getBeanList(user);
已有数据库时:
- private final String DATABASE_PATH = android.os.Environment
- .getExternalStorageDirectory().getAbsolutePath()
- + "/dictionary";
- //定义数据库的名字
- private final String DATABASE_FILENAME = "dictionary.db";
- private SQLiteDatabase openDatabase()
- {
- try
- {
- // 获得dictionary.db文件的绝对路径
- String databaseFilename = DATABASE_PATH + "/" + DATABASE_FILENAME;
- File dir = new File(DATABASE_PATH);
- // 如果/sdcard/dictionary目录中存在,创建这个目录
- if (!dir.exists())
- dir.mkdir();
- // 如果在/sdcard/dictionary目录中不存在
- // dictionary.db文件,则从res\raw目录中复制这个文件到
- // SD卡的目录(/sdcard/dictionary)
- if (!(new File(databaseFilename)).exists())
- {
- // 获得封装dictionary.db文件的InputStream对象
- InputStream is = getResources().openRawResource(
- R.raw.dictionary);
- FileOutputStream fos = new FileOutputStream(databaseFilename);
- byte[] buffer = new byte[8192];
- int count = 0;
- // 开始复制dictionary.db文件
- while ((count = is.read(buffer)) > 0)
- {
- fos.write(buffer, 0, count);
- }
- //关闭文件流
- fos.close();
- is.close();
- }
- // 打开/sdcard/dictionary目录中的dictionary.db文件
- SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(
- databaseFilename, null);
- return database;
- }
- catch (Exception e)
- {
- }
- //如果打开出错,则返回null
- return null;
- }
SQLiteDatabase的使用的更多相关文章
- Androide SQLiteDatabase数据库操作(转)
SQLite可以解析大部分的标准SQL语句:建表语句:create table 表名(主键名 integer primary key autoincrement(设置为自增列),其他列名及属性)或(主 ...
- SQLiteDatabase 基本操作
一.SQLiteOpenHelper类 android 提供类SQLiteOpenHelper帮助用户简化对SQLite数据库的操作.该类是一个抽象类,必须用户自己实现并重写oncreate()和on ...
- Android本地数据存储之SQLite关系型数据库 ——SQLiteDatabase
数据库的创建,获取,执行sql语句: 框架搭建:dao 思考: 1.数据库保存在哪里? 2.如何创建数据库?如何创建表? 3.如何更新数据库?如何更改表的列数据? 4.如何获取数据库? 5.如何修改数 ...
- SQLiteDatabase浅谈
(一).简介: Android通过 SQLite 数据库引擎来实现结构化数据的存储.在一个数据库应用程序中,任何类都可以通过名字对已经创建的数据库进行访问,但是在应用程序之外就不可以. SQLite ...
- Android——使用SQLiteDatabase操作SQLite数据库
除了可以使用文件或SharedPreferences存储数据,还可以选择使用SQLite数据库存储数据. 在Android平台上,集成了一个嵌入式关系型数据库-SQLite,SQLite3支持 NUL ...
- 数据库SQLiteDatabase
package com.baclock.entity; import android.provider.BaseColumns; /** * Created by Jack on 5/4/2016. ...
- SQLiteDatabase中的事务
beginTransaction():开始事务endTransaction():结束事务SQLiteDatabase还提供了如下方法来判断当前上下文是否处于事物环境中.inTransaction(): ...
- SQLiteDatabase里面的简单操作数据库的方法
1.使用insert方法插入记录SQLiteDatabase的insert方法的签名为long insert(String table,String nullColumnHack,ContentVal ...
- 使用SQLiteDatabase进行数据库操作的步骤
1.获取SQLiteDatabase对象,它代表了与数据库的连接.2.调用SQLiteDatabase的方法来执行SQL语句.3.操作SQL语句的执行结果,比如用SimpleCursorAdapter ...
- 关于android的SQLiteDatabase和Cursor的一些疑问
android数据库操作的基础有三个类:SQLiteOpenHelper,SQLiteDatabase和Cursor.其中,SQLiteOpenHelper会建立一个数据库连接,它虽然可以调用多次ge ...
随机推荐
- TensorFlow 安装详解
摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢! 『不要把手段当成目标 — <一个瑜伽行者的自传>』 本文提纲 1. 机器学习 2 ...
- 老李分享:性能测试你不应该只知道loadrunner(1)
老李分享:性能测试你不应该只知道loadrunner(1) poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.poptest测试 ...
- android开发用无线网络进行Android开发中的调试
1.手机具有root权限 2.安装adbWireless1.5.4.apk (下面有下载地址) 3.敲入命令:adb connect 192.168.1.127 后面是手机的IP地址 打开eclip ...
- 腾讯IVWEB团队:WebRTC 点对点直播
作者:villainthr 摘自:villainhr WebRTC 全称为:Web Real-Time Communication.它是为了解决 Web 端无法捕获音视频的能力,并且提供了 peer- ...
- js正则表达式匹配字符串与优化过程
前言 有时候需要实现对js源文件中的url字符串做拦截预处理,或者前端js语法高亮,或者需要对动态加载的关键源码做混淆保护,在某些步骤实现之前,有一个步骤是需要提炼出所有的合法字符串. 目标:检测源文 ...
- PHP初学者如何搭建环境,并在本地服务器(or云端服务器)运行自己的第一个PHP样例
页面底部有PHP代码样例供测试使用. 1.PHP开发,你需要什么? 1)开发代码的工具,可以用IDE名字叫做phpDesigner.当然也可以临时用记事本代替,记得文件扩展名为.php 2)服务器(本 ...
- get方式提交中文乱码(两次编码,一次解码)
1.编码XMLHttpRequest //建立连接 xmlhttp.open("get","${pageContext.request.contextPath}/serv ...
- Java高级特性(基础)
1.StringBuffer.StringBuilder和String一样,也用来代表字符串.String类是不可变类,任何对String的改变都 会引发新的String对象的生成:StringBuf ...
- 从Chrome源码看JS Array的实现
.aligncenter { clear: both; display: block; margin-left: auto; margin-right: auto } .crayon-line spa ...
- oracle表空间扩容
oracle在使用中会发现,表空间不足的情况:以下介绍了如何1.查询表空间使用率.剩余量:2.如何扩展表空间容量: 1.表空间容量指标查询 SELECT TABLESPACE_NAME "表 ...