我创建了一个 SqlLite 数据库程序,但每次它显示以下错误
没有找到这样的表
请告知为什么显示错误。
public static final String TOWN_ID="_id";
public static final String TOWN_NAME="name";
public static final String DISTT_ID="disttidd";
private static final String TAG="DbaAdapter";
private static final String DATABASE_NAME="mydb";
private static final String DATABASE_TABLE="tableetown";
private static final int DATABASE_VERSION=2;
private static final String DATABASE_CREATE="create table "+DATABASE_TABLE+"("+TOWN_ID+" int primary key ,"+TOWN_NAME+" text not null,"+DISTT_ID+" text not null)";
private final Context context;
private DatabaseHelper DBhelper;
private static SQLiteDatabase db;
public tableTown(Context ctx){
this.context=ctx;
DBhelper=new DatabaseHelper(context);
}
/* db=DBhelper.getWritableDatabase();
return this;
*
*/
private static class DatabaseHelper extends SQLiteOpenHelper{
DatabaseHelper(Context context){
super(context,DATABASE_NAME,null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
Log.w(TAG,"Upgrading database from version " + oldVersion +" to "+ newVersion+", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS tableTown");
onCreate(db);
}
}
public tableTown open() throws SQLException {
db=DBhelper.getWritableDatabase();
return this;
// TODO Auto-generated method stub
}
public Cursor fetchAllDistt() {
// TODO Auto-generated method stub
Cursor mCursor = db.query(DATABASE_TABLE, new String[] {TOWN_ID,TOWN_NAME,DISTT_ID}, null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
public void close() {
// TODO Auto-generated method stub
DBhelper.close();
}
}