数据库保存点播播放历史

果子TV:VideoPlayerActivity.java类中:

public void insertHistory() {
	if (sqlite == null) {
		sqlite = new SQLiteHelper(VideoPlayerActivity.this);
	}
	SQLiteDatabase db = sqlite.getWritableDatabase();
	if (db != null) {
		try {
                       //查找语句
			Cursor c = db.rawQuery("select * from historymedias  where  "
					+ MediaColumns.COL_ID + " = ?",
					new String[] { database_id });
			if (c.getCount() > 0) {
				handler.sendEmptyMessage(DATABASE_EXITS);
				return;
			}




			SQLiteStatement stat = db
					.compileStatement("INSERT INTO historymedias("
							+ MediaColumns.COL_ID + ","
							+ MediaColumns.COL_NAME + ","
							+ MediaColumns.COL_IMAGEURL + ","
							+ MediaColumns.COL_URL + ","
							+ MediaColumns.COL_CLASS
							+ ") VALUES(?,?,?,?,?)");
                             //index 为1开始索引,value为入库的值  bingXXX为插入XXX类型  
			int index = 1;
			stat.bindString(index++, database_id);// id
			stat.bindString(index++, database_name);// name
			stat.bindString(index++, database_imgUrl); // imgurl
			stat.bindString(index++, database_detailUrl); // url
			stat.bindString(index++, database_type);// class
			stat.execute();



                       //老式的数据插入,以上是优化后的插入代码
//			db.execSQL("INSERT INTO historymedias("
//					+ MediaColumns.COL_ID + ","
//					+ MediaColumns.COL_NAME + ","
//					+ MediaColumns.COL_IMAGEURL + ","
//					+ MediaColumns.COL_URL + ","
//					+ MediaColumns.COL_CLASS
//					+ ") VALUES(?,?,?,?,?)", 
//					new String[]{database_id,database_name,database_imgUrl,database_detailUrl,database_type});//				
			
			handler.sendEmptyMessage(DATABASE_SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			db.close();
		}
	}
}


以下也是一个查找语句:

                search.setOnClickListener(new OnClickListener()
		{
			//@Override
			public void onClick(View source)
			{
				// »ñÈ¡Óû§ÊäÈë
				String key = ((EditText) findViewById(R.id.key)).getText()
					.toString();
				// 查找word或detail的记录   and就是且,含有两者
				Cursor cursor = dbHelper.getReadableDatabase().rawQuery(
					"select * from dict where word like ? or detail like ?", 
					new String[]{"%" + key + "%" , "%" + key + "%"});
				
				//ŽŽœšÒ»žöBundle¶ÔÏó
				Bundle data = new Bundle();
				data.putSerializable("data", converCursorToList(cursor));
				//ŽŽœšÒ»žöIntent
				Intent intent = new Intent(Dict.this
					, ResultActivity.class);
				intent.putExtras(data);
				//Æô¶¯Activity
				startActivity(intent);
			}
		});









你可能感兴趣的:(数据库保存点播播放历史)