<bdo id='sn2cD'></bdo><ul id='sn2cD'></ul>

  • <legend id='sn2cD'><style id='sn2cD'><dir id='sn2cD'><q id='sn2cD'></q></dir></style></legend>

      <small id='sn2cD'></small><noframes id='sn2cD'>

    1. <i id='sn2cD'><tr id='sn2cD'><dt id='sn2cD'><q id='sn2cD'><span id='sn2cD'><b id='sn2cD'><form id='sn2cD'><ins id='sn2cD'></ins><ul id='sn2cD'></ul><sub id='sn2cD'></sub></form><legend id='sn2cD'></legend><bdo id='sn2cD'><pre id='sn2cD'><center id='sn2cD'></center></pre></bdo></b><th id='sn2cD'></th></span></q></dt></tr></i><div id='sn2cD'><tfoot id='sn2cD'></tfoot><dl id='sn2cD'><fieldset id='sn2cD'></fieldset></dl></div>

        <tfoot id='sn2cD'></tfoot>

        更新 SQLite 数据库 android

        时间:2023-07-09

          <small id='7E2cS'></small><noframes id='7E2cS'>

        • <tfoot id='7E2cS'></tfoot>
            <legend id='7E2cS'><style id='7E2cS'><dir id='7E2cS'><q id='7E2cS'></q></dir></style></legend>
          1. <i id='7E2cS'><tr id='7E2cS'><dt id='7E2cS'><q id='7E2cS'><span id='7E2cS'><b id='7E2cS'><form id='7E2cS'><ins id='7E2cS'></ins><ul id='7E2cS'></ul><sub id='7E2cS'></sub></form><legend id='7E2cS'></legend><bdo id='7E2cS'><pre id='7E2cS'><center id='7E2cS'></center></pre></bdo></b><th id='7E2cS'></th></span></q></dt></tr></i><div id='7E2cS'><tfoot id='7E2cS'></tfoot><dl id='7E2cS'><fieldset id='7E2cS'></fieldset></dl></div>
                <bdo id='7E2cS'></bdo><ul id='7E2cS'></ul>
                  <tbody id='7E2cS'></tbody>

                1. 本文介绍了更新 SQLite 数据库 android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  好的,我创建了一个数据库,我意识到每次我更改数据库中的某些内容时,我都必须卸载然后重新安装应用程序:(这非常令人沮丧...这是我的数据库代码,希望你能帮助我!我不知道我的代码有什么问题:

                  Okay, I made a database and i realised that each time i change something in the database i have to uninstall then reinstall the Application :( which is very frustrating... here is my code for my data base hopefully you can help me ! i dont know whats wrong with my code:

                  import android.content.ContentValues;
                  import android.content.Context;
                  import android.database.sqlite.SQLiteDatabase;
                  import android.database.sqlite.SQLiteOpenHelper;
                  
                  public class Cook_tab_snacks_data extends SQLiteOpenHelper {
                  
                  public static final String DATABASE_NAME = "Snacks";
                  
                  public Cook_tab_snacks_data(Context context) {
                      super(context, DATABASE_NAME, null, 1);
                  }
                  
                  @Override
                  public void onCreate(SQLiteDatabase db) {
                  
                      String sql = "CREATE TABLE IF NOT EXISTS snacks (" +
                                      "_id INTEGER PRIMARY KEY AUTOINCREMENT, " + 
                                      "name TEXT, " +
                                      "disc TEXT, " +
                                      "photo TEXT, " +
                                      "prep TEXT, " +
                                      "thumb TEXT, " +
                                      "ingre TEXT, " +
                                      "howto TEXT, " +
                                      "info TEXT, " +
                                      "snackId INTEGER)";
                      db.execSQL(sql);
                  
                      ContentValues values = new ContentValues();
                  
                      values.put("name", "Name 1");
                      values.put("disc", "here is the description");
                      values.put("photo", "stub.png");
                      values.put("thumb", "stub.png");
                      values.put("prep", "takes 30 mins");
                      values.put("ingre", "the ingredients of the snack");
                      values.put("howto", "how to make this thing");
                      values.put("info", "basically its this much calorie and such and such");
                      db.insert("snacks", "name", values);
                  
                      values.put("name", "Name 2");
                      values.put("disc", "here is the description");
                      values.put("photo", "stub.png");
                      values.put("thumb", "ic_launcher.png");
                      values.put("prep", "takes 500 mins");
                      values.put("ingre", "the ingredients of the snack");
                      values.put("howto", "how to make this thing");
                      values.put("info", "basically its this much calorie and such and such");
                      db.insert("snacks", "name", values);
                  
                      values.put("name", "Name 3");
                      values.put("disc", "here is the description");
                      values.put("photo", "stub.png");
                      values.put("thumb", "stub.png");
                      values.put("ingre", "the ingredients of the snack");
                      values.put("howto", "how to make this thing");
                      values.put("info", "basically its this much calorie and such and such");
                      db.insert("snacks", "name", values);
                  
                      values.put("name", "Name 4");
                      values.put("disc", "here is the description");
                      values.put("photo", "stub.png");
                      values.put("ingre", "the ingredients of the snack");
                      values.put("howto", "how to make this thing");
                      values.put("info", "basically its this much calorie and such and such");
                      db.insert("snacks", "name", values);
                  
                      values.put("name", "Name 5");
                      values.put("disc", "here is the description");
                      values.put("photo", "stub.png");
                      values.put("ingre", "the ingredients of the snack");
                      values.put("howto", "how to make this thing");
                      values.put("info", "basically its this much calorie and such and such");
                      db.insert("snacks", "name", values);
                  
                      values.put("name", "Name 6");
                      values.put("disc", "here is the description");
                      values.put("photo", "stub.png");
                      values.put("ingre", "the ingredients of the snack");
                      values.put("howto", "how to make this thing");
                      values.put("info", "basically its this much calorie and such and such");
                      db.insert("snacks", "name", values);
                  
                      values.put("name", "Name 7");
                      values.put("disc", "here is the description");
                      values.put("photo", "stub.png");
                      values.put("ingre", "the ingredients of the snack");
                      values.put("howto", "how to make this thing");
                      values.put("info", "basically its this much calorie and such and such");
                      db.insert("snacks", "name", values);
                  
                  }
                  
                  @Override
                  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                      db.execSQL("DROP TABLE IF EXISTS snacks");
                      onCreate(db);
                  }}
                  

                  我似乎无法添加任何项目,或编辑任何项目,而无需卸载应用程序然后重新安装:(请帮助!!!非常感谢!

                  I can't seem to add any item , or edit any item without having to unistall the application then reinstalling :( HELP PLEASE!!! thanks alot!

                  推荐答案

                  无需再次卸载和安装应用程序,只需增加数据库的版本号即可调用 onUpgrade 方法.

                  Instead of uninstalling and installing the application again, simply increment the version number of your database to call onUpgrade method.

                  public Cook_tab_snacks_data(Context context) {
                      super(context, DATABASE_NAME, null, 2);  //previously 1, now 2
                  }
                  

                  与您的 onUpgrade 方法一样,它首先会删除现有表,然后调用 onCreate 方法重新创建表

                  as in your onUpgrade method, first it will delete the existing table and then will call onCreate method to recreate the table(s)

                  这篇关于更新 SQLite 数据库 android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android:onUpgrade 不在数据库升级时调用 下一篇:Android 为现有数据库升级数据库的简单方法是什么

                  相关文章

                  <tfoot id='yteIL'></tfoot>
                  <i id='yteIL'><tr id='yteIL'><dt id='yteIL'><q id='yteIL'><span id='yteIL'><b id='yteIL'><form id='yteIL'><ins id='yteIL'></ins><ul id='yteIL'></ul><sub id='yteIL'></sub></form><legend id='yteIL'></legend><bdo id='yteIL'><pre id='yteIL'><center id='yteIL'></center></pre></bdo></b><th id='yteIL'></th></span></q></dt></tr></i><div id='yteIL'><tfoot id='yteIL'></tfoot><dl id='yteIL'><fieldset id='yteIL'></fieldset></dl></div>
                2. <small id='yteIL'></small><noframes id='yteIL'>

                    <legend id='yteIL'><style id='yteIL'><dir id='yteIL'><q id='yteIL'></q></dir></style></legend>
                    • <bdo id='yteIL'></bdo><ul id='yteIL'></ul>