您好,登錄后才能下訂單哦!
package com.android.provider;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
public class HelloContentProvider extends ContentProvider{
private static final UriMatcher um=new UriMatcher(UriMatcher.NO_MATCH);
private SQLiteDatabase sqlLite;
@Override
public int delete(Uri arg0, String arg1, String[] arg2) {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getType(Uri arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public Uri insert(Uri arg0, ContentValues arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean onCreate() {
// TODO Auto-generated method stub
um.addURI("com.android.provider","book",1);
sqlLite=SQLiteDatabase.openDatabase("/data/data/com.android.provider/tt", null,SQLiteDatabase.OPEN_READWRITE|SQLiteDatabase.CREATE_IF_NECESSARY);
sqlLite.execSQL("create table books([id] Integer primary key.autoincrement not null,[bookname] varchar(30) not null)");
ContentValues cv=new ContentValues();
cv.put("bookname", "android開發");
sqlLite.insert("books", null, cv);
return false;
}
@Override
public Cursor query(Uri uri, String[] arg1, String arg2, String[] arg3,
String arg4) {
// TODO Auto-generated method stub
if(um.match(uri)==1){
Cursor cursor=sqlLite.query("books", null, null, null, null, null, null);
return cursor;
}else{
return null;
}
}
@Override
public int update(Uri uri, ContentValues values, String arg2, String[] arg3) {
// TODO Auto-generated method stub
if(um.match(uri)==1){
int result=sqlLite.update("books", values, null, null);
}
return 0;
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。