android sqlite關於資料表的問題

來源:互聯網
上載者:User

標籤: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關於資料表的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.