馬上加入Android 台灣中文網,立即免費下載應用遊戲。
您需要 登錄 才可以下載或查看,沒有帳號?註冊
x
public class WInfoModel {
private static SQLiteDatabase db = null;
public static void setDb(SQLiteDatabase db) {
WInfoModel.db = db;
}
public static boolean save(WinFoData wid){
// 新增一- SQL語法
// 建立INSERT SQL語法
try {
String sql = String.format(
"INSERT INTO winfo values('%s',%f,%f,%f,%d)",
wid.getIN001(), wid.getIN002(), wid.getIN003(),
wid.getIN004(), wid.isIN005() ? 1 : 0);
db.execSQL(sql);
// 新增二- ContentValue物件
ContentValues cvs = new ContentValues();
cvs.put("IN001", wid.getIN001());
cvs.put("IN002", wid.getIN002());
cvs.put("IN003", wid.getIN003());
cvs.put("IN004", wid.getIN004());
cvs.put("IN005", wid.isIN005());
db.insertOrThrow("winfo", null, cvs);
} catch (SQLException ex) {
return false;
}
return true;
}
}
======================================================================
public class DBConnection extends SQLiteOpenHelper {
private final static String DB_NAME = "myDB";
private final static int DB_VERSION = 1;
public DBConnection(Context context) {
super(context, DB_NAME, null, DB_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String sql = "create table winfo(" +
"IN001 DATE PRIMARY KEY,"+ //測量日期
"IN002 DOUBLE,"+ //身高
"IN003 DOUBLE,"+ //體重
"IN004 DOUBLE,"+ //腰圍
"IN005 BOOLEAN)"; //性別
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
}
======================================================================
我就是看不懂這兩個類別的敘述 想請教大家
|