SQLite 数据库 *** 作类

SQLite 数据库 *** 作类,第1张

概述GoDB { private Database database; private SQLiteDatabase db; public GoosunDB(Context context) { super(); database = new Database(context); } public GoosunDB open() throws SQLException {
GoDB {  private Database database;	private sqliteDatabase db;	public GoosunDB(Context context) {		super();		database = new Database(context);	}	public GoosunDB open() throws sqlException {		db = database.getWritableDatabase();		return this;	}	public voID close() {		db.close();	}		public Cursor search(int mark) {		Cursor cursor = db.query(table_SEARCH,new String[] { Col_ID,Col_code,Col_name },"mark =" + mark,null,Col_date				+ " desc");		if (cursor != null) {			cursor.movetoFirst();		}		return cursor;	}	public Cursor searchByCode(String string) {		Cursor cursor = db.query(table_SEARCH,new String[] { Col_ID },"gID = " + "'" + string + "'",null);		if (cursor != null) {			cursor.movetoFirst();		}		return cursor;	}	public long insertEntity(SearchEntity entity) {				Cursor cursor = searchByCode(entity.getCode());		if (cursor != null && cursor.movetoFirst()) {			return updateEntity(entity);		} else {			ContentValues values = new ContentValues();			values.put(Col_code,entity.getCode());			values.put(Col_name,entity.getname());			values.put(Col_mark,entity.getMark());			values.put(Col_date,new Date().toString());			return db.insert(table_SEARCH,values);		}	}	public long updateEntity(SearchEntity entity) {		ContentValues values = new ContentValues();		values.put(Col_date,new Date().toString());		return db.update(table_SEARCH,values,"_ID=?",new String[] { String.valueOf(entity.getID()) });	}	public long deleteEntity(int mark) {		return db.delete(table_SEARCH,"mark=?",new String[] { String.valueOf(mark) });	}		private class Database extends sqliteOpenHelper {		public Database(Context context) {			super(context,DATABASE_name,DATABASE_VERSION);					}		@OverrIDe		public voID onCreate(sqliteDatabase db) {						db.execsql(table_InsIDeLetter);			db.execsql(table_CREATE);		}		@OverrIDe		public voID onUpgrade(sqliteDatabase db,int oldVersion,int newVersion) {						db.execsql("DROP table IF EXISTS" + table_SEARCH);			db.execsql("DROP table IF EXISTS" + table_InsIDe);			onCreate(db);		}	}}
总结

以上是内存溢出为你收集整理的SQLite 数据库 *** 作类全部内容,希望文章能够帮你解决SQLite 数据库 *** 作类所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/1170656.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存