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============
你插入的代码发来看看呢?
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。