??????????????????????????
???????????? ???????[ 2013/8/5 14:08:40 ] ????????
????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??????μ?
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11