Android中数据库升级
public class MySQLiteHelper extends SQLiteOpenHelper { public static final String span style=font-family: Arial, Helvetica, sans-serif;SQL_CREATE/spanspan style=font-family: Arial, Helvetica, sans-serif;= create table news ( /span + _id in
public class MySQLiteHelper extends SQLiteOpenHelper { public static final String <span style="font-family: Arial, Helvetica, sans-serif;">SQL_CREATE</span><span style="font-family: Arial, Helvetica, sans-serif;">= "create table news (" </span> + "_id integer primary key autoincrement, " + "nametext, " + "agetext, )"; public MySQLiteHelper(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(SQL_CREATE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }
当我们如上创建了个SQLiteHelper,我们知道会在本地的目录database中生成了个.db数据库文件! 可是我们遇到版本迭代往往要做更多的事情 这时候的会再创建个新的数据库
这时候我们编译完成之后发现没有在database相对应的目录下生成一个相对应的表。当然我们在调试代码的时候可以清楚应用数据这样重新运行的时候会把onCreate方法再次执行一次那当然就会把未生成成功的表生成出来,可以在用户迭代更新应用的时候总不能每次都清楚数据是吧! 所以:
<pre name="code" class="java">@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { onCreate(db); }
当然这种方法有一个很严重的弊端就是 可能我们在发布版本的时候忘记修改该version导致无法操作数据引起一系列不可收拾的bug。 所以推荐使用LitePal开源库进行对数据库操作! 详情可见 <a target=_blank href="http://http://blog.csdn.net/guolin_blog/article/details/39151617">点击打开链接</a>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

Samsung has not offered any hints yet about when it will update its Fan Edition (FE) smartphone series. As it stands, the Galaxy S23 FE remains the company's most recent edition, having been presented at the start of October 2023. However, plenty of

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

The Redmi Note 14 Pro Plus is now official as a direct successor to last year'sRedmi Note 13 Pro Plus(curr. $375 on Amazon). As expected, the Redmi Note 14 Pro Plus heads up the Redmi Note 14 series alongside theRedmi Note 14and Redmi Note 14 Pro. Li

Historically, Oppo has refreshed its flagship 'Find X' series in late winter or early spring, save for the original Find X that it announced in June 2018. To that end, the Find X7 and Find X7 Ultra are barely more than six months old at this point. H

It seems that the launch of a new entry-level Galaxy A series smartphone could be in the offing. Although Samsung has not officially announced anything just yet, Android Headlines has already published render images of what it claims is a Galaxy A15

Xiaomi has just announced the release date for its next Redmi Note smartphones. As expected, these are set to arrive as three Redmi Note 14 series handsets. More specifically, the company intends to release the Redmi Note 14, Redmi Note 14 Pro and Re

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.
