????1??????????????????  DButil.java

???????????£?

package com.dd.dd.util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DButil extends SQLiteOpenHelper {
 private static final int VERSION = 1; // ???????汾???
 private static final String DBNAME = "school.db";// ???????????????????
 private static final String TAG = "DButil"; // ???????????????

 public DButil(Context context) { // ??????????????Content???????
  super(context?? DBNAME?? null?? VERSION); // ???????
 }

 @Override
 public void onCreate(SQLiteDatabase db) { // ????????????????????????????????????
  Log.i(TAG?? "???onCreate()????");
  db.execSQL("create table student (id integer primary key??name varchar(20))"); // ??????
  Log.i(TAG?? "?????onCreate()????");
 }

 @Override
 public void onUpgrade(SQLiteDatabase db?? int oldVersion?? int newVersion) { // ????????????汾??
 }

}

????2??????????????dao??dao??????javaee??????????????????????????StudentDao

???????????£?

package com.dd.dd.dao;

import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.dd.dd.model.Student;
import com.dd.dd.util.DButil;

public class StudentDao {
 private DButil helper;
 private SQLiteDatabase db;
 private static final String TAG = "StudentDao"; // ????????????????????????????????????

 public StudentDao(Context context) {
  helper = new DButil(context); // ????????????????????????????????DButil.java
 }

 // ???
 public void add(Student student) {
  db = helper.getWritableDatabase();  //????getWritableDatabase()
  Log.i(TAG?? student.getName() + student.getId());  //???????????????????????
  db.execSQL("insert into student (id??name) values(????)"?? new Object[] {
    student.getId()?? student.getName() }); //?????????????????mysql??????μ?
 }

}