1、我昨天的成就:成功连接上数据库
2、遇到什么困难:一些语句的操作看不懂,里面有很多不懂得参数
3、今天的任务:实现能查看数据库,让数据可视化。
package com.example.lenovo.share; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class DbHelper extends SQLiteOpenHelper { private static final String DB_NAME = "share.db"; private static final String TBL_NAME = "user"; private static final String CREATE_TBL = "create table user " + "(username varchar(20) primary key ,password varchar(20))"; private SQLiteDatabase db; public DbHelper(Context context) { super(context, DB_NAME, null, 1); } public DbHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { super(context, name, factory, 1); } @Override public void onCreate(SQLiteDatabase db) { //创建数据库及表格 db.execSQL(CREATE_TBL); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } public void open() { db = getWritableDatabase(); } public void close() { if (db != null) { db.close(); } } }