Android打开SQList失败,新手求解
[img=http://][/img]
import android.net.Uri;
import android.provider.BaseColumns;
public interface databaseMataData {
//这个是外部访问的AUTHORITY,Content地址为:content//com.example.contentprovider.membercontentprovider
public static final String AUTHORITY="com.example.contentprovider.membercontentprovider";
//数据库名字
public static final String DATABASE_NAME="test";
//数据库版本
public static final int VERSION=1;
public static interface MeberTableMetaData extends BaseColumns{
public static final String TABLE_NAME="member";//表名称
public static final Uri CONTENT_URI=Uri.parse("content://"+AUTHORITY+"/"+TABLE_NAME);//表的Uri地址
//得到member表中的全部记录
public static final String CONTENT_LIST="vnd.android.cursor.dir/vnd.contentprovider.member";
//取得一个member信息,相当于按ID查询
public static final String CONTENT_ITEM="vnd.android.cursor.item/vnd.contentprovider.member";
public static final String MEMBER_NAME="name";
public static final String MEMBER_AGE="age";
public static final String MEMBER_BIRTHDAY="birthday";
public static final String SORT_ORDER="_id DESC";//排序操作
}
}
package com.example.contentprovider;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class MydatabaseHelper extends SQLiteOpenHelper {
/*
* private static final String DATABASENAME="test.db"; private static final
* int DATABASEVERSION=1; private static final String TABLENAME="member";
*/
public MydatabaseHelper(Context context) {
super(context, databaseMataData.DATABASE_NAME, null,
databaseMataData.VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE"
+ databaseMataData.MeberTableMetaData.TABLE_NAME + "("
+ databaseMataData.MeberTableMetaData._ID
+ "INTEGER PRIMARY KEY,)"
+ databaseMataData.MeberTableMetaData.MEMBER_NAME
+ "VARCHAR(50) NOT NULL,"
+ databaseMataData.MeberTableMetaData.MEMBER_AGE
+ "INTEGER NOT NULL,"
+ databaseMataData.MeberTableMetaData.MEMBER_BIRTHDAY
+ "VARCHAR(50) NOT NULL";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String sql = "DROP TABLE IF EXISTS"
+ databaseMataData.MeberTableMetaData.TABLE_NAME;
db.execSQL(sql);
this.onCreate(db);
}
}
// 增加
@Override
public Uri insert(Uri uri, ContentValues values) {
SQLiteDatabase db=this.helper.getWritableDatabase();//以写方式打开数据库
long id=0;//取得增长后的数据id
switch(uriMatcher.match(uri)){
case GET_MEMBER_LIST:
return null;
case GET_MEMBER_ITEM:
System.out.println("GET_MEMBER_ITEM");
/*id=db.insert(databaseMataData.MeberTableMetaData.TABLE_NAME, databaseMataData.MeberTableMetaData._ID, values);
String uriPath=uri.toString();
System.out.println("****"+uriPath+id);*/
return null;
}
return null;
}
String sql = "CREATE TABLE "
+ databaseMataData.MeberTableMetaData.TABLE_NAME + " ( "
+ databaseMataData.MeberTableMetaData._ID
+ " INTEGER PRIMARY KEY,"
+ databaseMataData.MeberTableMetaData.MEMBER_NAME
+ " VARCHAR(50) NOT NULL,"
+ databaseMataData.MeberTableMetaData.MEMBER_AGE
+ " INTEGER NOT NULL," + databaseMataData.MeberTableMetaData.MEMBER_BIRTHDAY
+ " VARCHAR(50) NOT NULL" + " )";