您好,登录后才能下订单哦!
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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。