android中跨项目的数据库操作ContentProvider的使用
RuiXin.java类
[html]
package com.gtl.data.two;
import android.net.Uri;
public class RuiXin {
public static final String DBNAME = "ruixinonlinedb";
public static final String TNAME = "ruixinonline";
public static final int VERSION = 3;
public static String TID = "tid";
public static final String USERNAME = "username";
public static final String DATE = "date";
public static final String SEX = "易做图";
public static final String AUTOHORITY = "com.gtl.data.two";
public static final int ITEM = 1;
public static final int ITEM_ID = 2;
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.ruixin.login";
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.ruixin.login";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTOHORITY + "/ruixinonline");
}
package com.gtl.data.two;
import android.net.Uri;
public class RuiXin {
public static final String DBNAME = "ruixinonlinedb";
public static final String TNAME = "ruixinonline";
public static final int VERSION = 3;
public static String TID = "tid";
public static final String USERNAME = "username";
public static final String DATE = "date";
public static final String SEX = "易做图";
public static final String AUTOHORITY = "com.gtl.data.two";
public static final int ITEM = 1;
public static final int ITEM_ID = 2;
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.ruixin.login";
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.ruixin.login";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTOHORITY + "/ruixinonline");
}
DBlite.java类
[html
package com.gtl.data.two;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBlite extends SQLiteOpenHelper {
public DBlite(Context context) {
super(context, RuiXin.DBNAME, null, RuiXin.VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table "+RuiXin.TNAME+"(" +
RuiXin.TID+" integer primary key autoincrement not null,"+
RuiXin.USERNAME+" text not null," +
RuiXin.DATE+" interger not null,"+
RuiXin.SEX+" text not null);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+RuiXin.TNAME);
onCreate(db);
}
public void add(String username,String date,String 易做图){
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(RuiXin.USERNAME, username);
values.put(RuiXin.DATE, date);
values.put(RuiXin.SEX, 易做图);
db.insert(RuiXin.TNAME,"",values);
}
public void del(){
SQLiteDatabase db = getWritableDatabase();
db.delete(RuiXin.TNAME,RuiXin.DATE+"=?" , new String[]{"time=1368497000287"});
}
public void update(){
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(RuiXin.USERNAME, "louis koo");
values.put(RuiXin.DATE, "today");
values.put(RuiXin.SEX, "男");
db.update(RuiXin.TNAME, values, RuiXin.DATE+"=?" , new String[]{"time=1368497006097"});
}
}
package com.gtl.data.two;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBlite extends SQLiteOpenHelper {
public DBlite(Context context) {
super(context, RuiXin.DBNAME, null, RuiXin.VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table "+RuiXin.TNAME+"(" +
RuiXin.TID+" integer primary key autoincrement not null,"+
RuiXin.USERNAME+" text not null," +
RuiXin.DATE+" interger not null,"+
RuiXin.SEX+" text not null);");
}
@Override
public
补充:移动开发 , Android ,