在 Android 里使用数据库
2010-02-24 04:45:00 来源:WEB开发网import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.widget.TextView;
public class AaBbActivity extends Activity {
/** Called when the activity is first created. 中 */
private static final String DATABASE_NAME = "con_tact.db";
private static final int DATABASE_VERSION = 2;
private static final String CONT_TABLE_NAME = "cont";
private static final String COL_NAME = "name";
private static final String COL_TEL = "tel";
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + CONT_TABLE_NAME + " ("
+ BaseColumns._ID + " INTEGER PRIMARY KEY,"
+ COL_NAME + " TEXT,"
+ COL_TEL + " TEXT"
+ ");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
// + newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS notes");
onCreate(db);
}
}
private DatabaseHelper mOpenHelper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this); // 定义一个TextView用来显示到屏幕上
setContentView(tv);
- ››Android 当修改一些代码时,使用什么编译命令可以最...
- ››Android 如何添加一个apk使模拟器和真机都编译进去...
- ››Android 修改Camera拍照的默认保存路径
- ››Android 如何修改默认输入法
- ››android开发中finish()和System.exit(0)的区别
- ››Android手势识别简单封装类
- ››android中查看项目数字证书的两种方法
- ››Android中获取IMEI码的办法
- ››android 相机报错 setParameters failed
- ››Android重启运用程序的代码
- ››Android为ListView的Item设置不同的布局
- ››android bitmap与base64字符串的互相转换
更多精彩
赞助商链接