SQLite的小例子--备忘录(3)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-20 07:51 点击:次
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
public class MyAdapter {
public static final String KEY_ROWID = "_id";
public static final String KEY_CATEGORY = "category";
public static final String KEY_SUMMARY = "summary";
public static final String KEY_DESCRIPTION = "description";
public static final String DATABASE_TABLE = "test";
private Context context;
private SQLiteDatabase db;
private MySQLiteOpenHelper dbHelper;
public MyAdapter(Context context)
{
this.context = context;
}
public MyAdapter open() throws SQLException
{
dbHelper = new MySQLiteOpenHelper(context);
db = dbHelper.getWritableDatabase();
return this;
}
public void close()
{
dbHelper.close();
}
/**
* 创建一个新的标test,如果test成功创建则返回一个新的列id,否则返回-1来表示失败
*/
public long createTest(String category, String summary, String description)
{
ContentValues initialValues = createContentValues(category, summary, description);
return db.insert(DATABASE_TABLE, null, initialValues);
}
//更新表test
public boolean updateTest(long rowId, String category, String summary, String description)
{
ContentValues updateValues = createContentValues(category, summary, description);
return db.update(DATABASE_TABLE, updateValues, KEY_ROWID + "=" +rowId, null)>0;
}
//删除表test
public boolean deleteTest(long rowId)
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>