標籤:android io ar sp 資料 on 問題 代碼 ad
============問題描述============
我在程式裡建立了兩個資料庫,“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關於資料表的問題