Andriod的SQLite以及对于当前android的学习总结
对于SQLiteHelper的应用
package com.example.helloworld;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import data.User;
public class UserSQLHelper extends SQLiteOpenHelper {
private static final String name="uer.db";
private static final int version=1;
private static UserSQLHelper mHelper=null;
private SQLiteDatabase mRDB=null;
private SQLiteDatabase mWDB=null;
private UserSQLHelper(Context context){
super(context,name,null,version);
}
public static UserSQLHelper getInstance(Context context){
if(mHelper==null){
mHelper=new UserSQLHelper(context);
}
return mHelper;
}
//数据库读连接
public SQLiteDatabase openReadLink(){
if(mRDB==null||!mRDB.isOpen()){
mRDB=mHelper.getReadableDatabase();
}
return mRDB;
}
//数据库写连接
private SQLiteDatabase openWriteLink(){
if(mWDB==null||!mWDB.isOpen()){
mWDB=mHelper.getWritableDatabase();
}
return mWDB;
}
//关闭连接
private void closeLink(){
if(mRDB!=null&&mRDB.isOpen()){
mRDB.close();
mRDB=null;
}
if(mWDB!=null&&mWDB.isOpen()){
mWDB.close();
mWDB=null;
}
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql="create table if not exists users(" +
"id varchar," +
"password varchar);";
db.execSQL(sql);
}
//版本升级
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
//插入
public void insert(User user){
ContentValues values=new ContentValues();
values.put("id",user.getId());
values.put("password",user.getPassword());
mWDB.insert(name,null,values);
}
}
当前对于android的布局,内置的数据库sqlite,页面跳转和项目文件有了一定的了解,可以针对配置的需要进行修改,避免出现软件包解析不成功等问题。