day_moon 2015-07-10 01:43 采纳率: 0%
浏览 1609
已采纳

context里面有什么的内容

在StudentDao类文件中代码如下:

public class StudentDao {

Context context;
final String tableName = "student";

public StudentDao(Context mContext) {
    context = mContext;
}

// 添加
public void addStudent(Student student) {
    DbUtil mDbUtil = new DbUtil(context);
    SQLiteDatabase mSQLiteDatabase = mDbUtil.getWritableDatabase();
    // 执行insert语句的方式
    ContentValues values = new ContentValues();
    values.put("id", student.getId());
    values.put("age", student.getAge());
    values.put("name", student.getName());
    mSQLiteDatabase.insert(tableName, null, values);
    // 关闭
    mSQLiteDatabase.close();
    mDbUtil.close();
}
}

在DbUtil类文件中代码如下:
public class DbUtil extends SQLiteOpenHelper {

//创建库文件
public DbUtil(Context context) {
super(context, "test.db", null, 2);
}
//创建表
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table student(id int,name varchar(20))");
db.execSQL("create table teacher(id int,name varchar(20))");
Log.e("DbUtil", "onCreate");

}
}

问题1:在StudentDao类中,StudentDao构造函数有什么作用(可以说详细一点吗)?
问题2:在StudentDao类中,这一句代码DbUtil mDbUtil = new DbUtil(context)这一句代码是创建一个数据库吗?
  • 写回答

5条回答

  • 咖啡_K 2015-07-10 10:48
    关注

    问题1:在StudentDao类中,StudentDao构造函数有什么作用?

    就是传进来一个数据库对象(如test.db),然后看情况调用里面的方法(addStudent)

    问题2:在StudentDao类中,这一句代码DbUtil mDbUtil = new DbUtil(context)这一句代码是创建一个数据库吗?

    创建context这个对象(test.db)的数据库

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器