iT邦幫忙

0

android studio SQLite新增欄位失敗

  • 分享至 

  • xImage

原本只有4個欄位,後來新增2個欄位跟修改1個欄位之後就跑不出來了,剩原本那兩個欄位可以新增,有爬文照著新增,但不知道哪裡寫錯,請大老們幫看看!!

public class DBHelper extends SQLiteOpenHelper {
    private final static int DBVersion = 3;
    private final static String DBName = "SampleList.db";

    private final static String TableName = "MySample";

    public DBHelper(Context context, String name, SQLiteDatabase.CursorFactory factory,
                    int version) {
        super(context, name, factory, version);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String SQLTable = "CREATE TABLE IF NOT EXISTS " + TableName +
                "(" +
                "_id INTEGER PRIMARY KEY AUTOINCREMENT," +
                "Name TEXT," +
                "Phone TEXT," +
                "BloodType TEXT," +
                "Birthday TEXT," +
                "Address TEXT," +
                "ElseInfo TEXT" +
                ");";
        db.execSQL(SQLTable);
        // 產生資料表的 SQL 寫在這 onCreate
        // 如果 Android 載入時找不到生成的資料庫檔案,就會觸發 onCreate
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        final String SQL = "DROP TABLE " + TableName;
        db.execSQL(SQL);

        // onUpgrade 則是如果資料庫結構有改變了就會觸發 onUpgrade

    }
GHH iT邦新手 1 級 ‧ 2023-08-17 10:05:35 檢舉
請貼錯誤訊息
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答