我是新手 最近自己尝试做个小程序。关于一个数据库建多张表 小弟查阅一下,也不能得到解决,求高手指教下。
public void onCreate(SQLiteDatabase db) {
String sqlCalendar = "CREATE TABLE IF NOT EXISTS calendar(pid integer primary key autoincrement," +
"moon varchar(4)," +
"day varchar(4)," +
"year varchar(4)," +
"hints varchar(8)," +
"sort varchar(4)," +
"tag text," +
"memorialDay varchar(4))";
db.execSQL(sqlCalendar);
String sqlSpend = "CREATE TABLE IF NOT EXISTS spend(spendid integer primary key autoincrement," +
"moon varchar(4)," +
"day varchar(4)," +
"year varchar(4)," +
"spendsort varchar(8)," +
"spend varchar(4))";
db.execSQL(sqlSpend);
}
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS calendar");
db.execSQL("DROP TABLE IF EXISTS spend");
onCreate(db);
}
以上是帮助类的代码部分,服务部分的代码
public boolean insert(ScheduleDateTag sdt) {
boolean flag = false;
ContentValues values = new ContentValues();
values.put("moon", sdt.getMoon());
values.put("day", sdt.getDay());
values.put("year", sdt.getYear());
values.put("hints", sdt.getHints());
values.put("sort", sdt.getSort());
values.put("memorialDay", sdt.isMemorialDay());
values.put("tag", sdt.getWorkingTag());
try {
db.insert("calendar", null, values);
flag = true;
} catch (Exception e) {
flag = false;
}
return flag;
}
public boolean insert(SpendDateTag sdt) {
boolean flag = false;
db = dbOpenHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("moon", sdt.getMoon());
values.put("day", sdt.getDay());
values.put("year", sdt.getYear());
values.put("spendsort", sdt.getSpendSort());
values.put("spend", sdt.getSpend());
try {
db.insert("spend", null, values);
flag = true;
} catch (Exception e) {
flag = false;
}
return flag;
}
这里创建calendar表可以创建,但是spend表创建不了,错误提示
android.database.sqlite.SQLiteException: no such table: spend (code 1): , while compiling: INSERT INTO spend(year,moon,day,spendsort,spend) VALUES (?,?,?,?,?)
求大神指教