我是新手 最近自己尝试做个小程序。关于一个数据库建多张表 小弟查阅一下,也不能得到解决,求高手指教下。
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 (?,?,?,?,?)
求大神指教
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。