首页 > 代码库 > android sqlite关于数据表的问题
android sqlite关于数据表的问题
============问题描述============
我在程序里新建了两个数据库,“book.db”和"book4.db",然后分别在其中新增了一张数据表“localbook”和"localbook4",结果在程序运行时,两张表都可以新建,但是当我向一张表中插入数据以后,另一张表就无法插入(空表,不报错),求解!
以下是我两个SQLiteOpenHelper类的代码:
第一个LocalBook类:
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class LocalBook extends SQLiteOpenHelper {
private static String DATABASE_NAME = "book.db";
private static int DATABASE_VERSION = 1;
private String PATH = "path";
private String TYPE = "type";
public LocalBook(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE " + "localbook" + " ( parent text not null, " + PATH
+ " text not null, " + TYPE + " text not null"
+ ", now text not null, ready)";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("drop table localbook");
onCreate(db);
}
}
第二个LocalBook4类:
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class LocalBook4 extends SQLiteOpenHelper {
private static String DATABASE_NAME = "book4.db";
private static int DATABASE_VERSION = 1;
private String PATH = "path";
private String TYPE = "type";
public LocalBook4(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE " + "localbook4" + " ( parent text not null, " + PATH
+ " text not null, " + TYPE + " text not null"
+ ", now text not null, ready)";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("drop table localbook4");
onCreate(db);
}
}
============解决方案1============
你插入的代码发来看看呢?
android sqlite关于数据表的问题
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。