我已经在网上搜索以解决我的问题,但我找到的解决方案都没有为我工作,所以这是我的问题。
我有道:
public class AqntCategoryDAO extends SQLiteOpenHelper{
public static abstract class AqntCategoryEntry implements BaseColumns {
public static final String TABLE_NAME = "category";
public static final String COLUMN_NAME_NAME = "name";
public static final String COLUMN_NAME_TAG = "tag";
public static final String COLUMN_NAME_STATUS = "status";
}
//globals
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "AquiNaoTemPlaces.db";
public static String[] columns = {
AqntCategoryEntry._ID,
AqntCategoryEntry.COLUMN_NAME_NAME,
AqntCategoryEntry.COLUMN_NAME_TAG,
AqntCategoryEntry.COLUMN_NAME_STATUS
};
public AqntCategoryDAO(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
StringBuffer sql_create = new StringBuffer();
sql_create.append("CREATE TABLE IF NOT EXISTS "+AqntCategoryEntry.TABLE_NAME);
sql_create.append("( ");
sql_create.append(AqntCategoryEntry._ID+" INTEGER PRIMARY KEY AUTOINCREMENT,");
sql_create.append(AqntCategoryEntry.COLUMN_NAME_NAME+" TEXT,");
sql_create.append(AqntCategoryEntry.COLUMN_NAME_TAG+" TEXT,");
sql_create.append(AqntCategoryEntry.COLUMN_NAME_STATUS+" INTEGER");
sql_create.append(" )");
Log.i("SQL: ",sql_create.toString());
db.execSQL(sql_create.toString());
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + AqntCategoryEntry.TABLE_NAME);
onCreate(db);
}
...
和:
public class AqntPlacesDAO extends SQLiteOpenHelper{
public static abstract class AqntPlacesEntry implements BaseColumns {
public static final String TABLE_NAME = "places";
public static final String COLUMN_NAME_NAME = "name";
public static final String COLUMN_NAME_LATITUDEE6 = "latitudeE6";
public static final String COLUMN_NAME_LONGITUDEE6 = "longitudeE6";
public static final String COLUMN_NAME_RATE = "rate";
public static final String COLUMN_NAME_STATUS = "status";
}
//globals
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "AquiNaoTemPlaces.db";
public static String[] columns = {
AqntPlacesEntry._ID,
AqntPlacesEntry.COLUMN_NAME_NAME,
AqntPlacesEntry.COLUMN_NAME_LATITUDEE6,
AqntPlacesEntry.COLUMN_NAME_LONGITUDEE6,
AqntPlacesEntry.COLUMN_NAME_RATE,
AqntPlacesEntry.COLUMN_NAME_STATUS
};
public AqntPlacesDAO(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
StringBuffer sql_create = new StringBuffer();
sql_create.append("CREATE TABLE IF NOT EXISTS "+AqntPlacesEntry.TABLE_NAME);
sql_create.append("( ");
sql_create.append(AqntPlacesEntry._ID+" INTEGER PRIMARY KEY AUTOINCREMENT,");
sql_create.append(AqntPlacesEntry.COLUMN_NAME_NAME+" TEXT,");
sql_create.append(AqntPlacesEntry.COLUMN_NAME_LATITUDEE6+" TEXT,");
sql_create.append(AqntPlacesEntry.COLUMN_NAME_LONGITUDEE6+" TEXT,");
sql_create.append(AqntPlacesEntry.COLUMN_NAME_RATE+" REAL,");
sql_create.append(AqntPlacesEntry.COLUMN_NAME_STATUS+" INTEGER");
sql_create.append(" )");
Log.i("SQL: ",sql_create.toString());
db.execSQL(sql_create.toString());
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF `EXISTS` " + AqntPlacesEntry.TABLE_NAME);
onCreate(db);
}
...
当我尝试
AqntPlacesDAO daoPlace = new AqntPlacesDAO(context);
AqntCategoryDAO catAuxDAO = new AqntCategoryDAO(context);
List<AqntPlaces> places = daoPlace.getPlaces();
List<AqntCategory> catss = catAuxDAO.getCategories();
daoPlace.close();
catAuxDAO.close();
它只创建第一个,另一个向我显示错误:
02-19 22:51:29.083: E/AndroidRuntime(9336): android.database.sqlite.SQLiteException: no such table: category: , while compiling: SELECT _id, name, tag, status FROM category
但如果我只运行一个 DAO,它就可以工作。
有人知道我在做什么错吗?