android 数据库
16lz
2021-01-23
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class StudentDBHelper extends SQLiteOpenHelper {
private static SQLiteDatabase db = null;
private static final String TAG = "StudentDB";
private static final String DATABASE_NAME = "studentss.db";
private static final int Version = 1;
public static final String TABLE_NAME = "STUDENT_TABLE";
private static final String base_info = "create table "
+ TABLE_NAME
+ "(name text not null,sex text,age text,no text,phone text,address text);";
private StudentDBHelper(Context context) {
super(context, DATABASE_NAME, null,
Version);
Log.i(TAG, "database is create");
}
public static SQLiteDatabase getSQLiteDatabse(Context context) {
db = new StudentDBHelper(context).getWritableDatabase();
return db;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(base_info);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.i(TAG, "onUpgrade database");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class StudentDBHelper extends SQLiteOpenHelper {
private static SQLiteDatabase db = null;
private static final String TAG = "StudentDB";
private static final String DATABASE_NAME = "studentss.db";
private static final int Version = 1;
public static final String TABLE_NAME = "STUDENT_TABLE";
private static final String base_info = "create table "
+ TABLE_NAME
+ "(name text not null,sex text,age text,no text,phone text,address text);";
private StudentDBHelper(Context context) {
super(context, DATABASE_NAME, null,
Version);
Log.i(TAG, "database is create");
}
public static SQLiteDatabase getSQLiteDatabse(Context context) {
db = new StudentDBHelper(context).getWritableDatabase();
return db;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(base_info);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.i(TAG, "onUpgrade database");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer