1.zip

  • 祈万万星辰
    了解作者
  • Java
    开发工具
  • 345KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2021-04-16 18:07
    上传日期
安卓pc摄像头摄像数据在手机同步显示的源码
1.zip
内容介绍
package com.xmobileapp.cammonitor.util; import java.util.ArrayList; import java.util.List; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; import com.xmobileapp.cammonitor.R; import com.xmobileapp.cammonitor.config.CamMonitorParameter; public class DatabaseHelper{ static class Helper extends SQLiteOpenHelper { protected final static String TAG ="DatabaseHelper"; private final static String DATABASE_NAME="CAMMONITOR_CLIENT"; private final static int DATABASE_VERSION = 1; private Context context; public Helper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); this.context = context; } public void onCreate(SQLiteDatabase db) { try{ String sql =context.getString(R.string.table_sql); db.execSQL(sql); Log.i(TAG, sql); }catch (Exception e) { // TODO: handle exception } } public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { String sql = context.getString(R.string.drop_sql); db.execSQL(sql); this.onCreate(db); } } private Context context; protected SQLiteDatabase db; public DatabaseHelper(Context context) { this.context = context; db = new Helper(context).getWritableDatabase();; } public static CamMonitorParameter query(Context context,int id) throws Exception{ SQLiteDatabase db = null; try{ db = new Helper(context).getWritableDatabase(); String whereClause = " _id = ?"; String[] whereArgs = new String[] {String.valueOf(id)}; String[] columns = new String[]{ "name", "ip","port","username","password","client_dir","connect_type" }; Cursor cursor = db.query("tb_cammonitor_configs", columns, whereClause, whereArgs, null, null, null); if(cursor.getCount()==0){ throw new Exception("没有找到ID"+id+"的数据"); } cursor.moveToFirst(); CamMonitorParameter param = new CamMonitorParameter(); param.setId(id); param.setName(cursor.getString(0)); param.setIp(cursor.getString(1)); param.setPort(cursor.getInt(2)); param.setUsername(cursor.getString(3)); param.setPassword(cursor.getString(4)); param.setLocal_dir(cursor.getString(5)); return param; }catch (Exception e) { throw e; }finally{ if(db!=null){ db.close(); } } } public static long testInsert(Context context){ SQLiteDatabase db = null; try{ db = new Helper(context).getWritableDatabase(); ContentValues values = new ContentValues(); // values.put("_id", -1); values.put("name", "test1"); values.put("port", 21); values.put("ip", "192.168.18.3"); values.put("username", "test"); values.put("password", "test"); values.put("client_dir", "test"); long num = db.insert("tb_cammonitor_configs", null, values); return num; }finally{ if(db!=null){ db.close(); } } } public static long insert(Context context,String table,ContentValues values) throws Exception{ SQLiteDatabase db = null; try{ db = new Helper(context).getWritableDatabase(); long num = db.insert(table, null, values); return num; }catch (Exception e) { throw e; } finally{ if(db!=null){ db.close(); } } } public static long update(Context context,String table,ContentValues values,int id) throws Exception{ SQLiteDatabase db = null; try{ db = new Helper(context).getWritableDatabase(); String whereClause = " _id = ?"; String[] whereArgs = new String[] {String.valueOf(id)}; long num = db.update(table, values, whereClause, whereArgs); return num; }catch (Exception e) { throw e; } finally{ if(db!=null){ db.close(); } } } public static void testDelete(Context context){ SQLiteDatabase db = null; try{ Helper helper = new Helper(context); db = helper.getWritableDatabase(); db.execSQL("delete from tb_cammonitor_configs;"); }finally{ if(db!=null){ db.close(); } } } public static void delete(Context context,int id) throws Exception{ SQLiteDatabase db = null; try{ Helper helper = new Helper(context); db = helper.getWritableDatabase(); String table = "tb_cammonitor_configs"; String whereClause = " _id = ?"; String[] whereArgs = new String[] {String.valueOf(id)}; db.delete(table, whereClause, whereArgs); }catch (Exception e) { throw e; } finally{ if(db!=null){ db.close(); } } } public static void drop(Context context){ SQLiteDatabase db = null; try{ db = new Helper(context).getWritableDatabase(); String sql =context.getString(R.string.drop_sql); db.execSQL(sql); }finally{ if(db!=null){ db.close(); } } } public static int getCount(Context context ,String table) throws Exception{ SQLiteDatabase db = null; try{ db = new Helper(context).getReadableDatabase(); Cursor cur = db.query(table, new String[]{"_id","name"}, null, null, null, null, null); return cur.getCount(); }catch (Exception e) { throw e; }finally{ if(db!=null){ db.close(); } } } public Cursor loadAllName() throws Exception{ try{ Cursor cur = db.query("tb_cammonitor_configs", new String[]{"_id","name"}, null, null, null, null, "_id DESC"); return cur; }catch (Exception e) { throw e; } } public void close(){ if(this.db!=null){ this.db.close(); } } public static List<String> loadName(Context context) throws Exception{ SQLiteDatabase db = null; List<String> rst = new ArrayList<String>(); try{ db = new Helper(context).getReadableDatabase(); Cursor cur =db.query("tb_cammonitor_configs", new String[]{"_id","name"}, null, null, null, null, null); cur.moveToFirst(); for (int i = 0; i < cur.getCount(); i++) { String s = cur.getString(1); rst.add(s); cur.moveToNext(); } return rst; }catch (Exception e) { throw e; }finally{ if(db!=null){ db.close(); } } } public Cursor query(int id) throws Exception{ try{ String whereClause = " _id = ?"; String[] whereArgs = new String[] {String.valueOf(id)}; Cursor cur = db.query("tb_cammonitor_configs", new String[]{"_id","name","ip","port","username","password","client_dir"}, whereClause, whereArgs, null, null, "_id DESC"); return cur; }catch (Exception e) { throw e; } } }
评论
    相关推荐
    • Android代码-Android Dialog 安卓对话框
      Android Dialog 安卓对话框 Android Dialog 即 Android对话框,在Android开发中,我们经常会需要在Android界面上弹出一些对话框,以询问用户或者让用户选择。Android Dialog 一般有五种,分别是:一般对话框,列表...
    • android安卓计算器
      android计算器 表达式运算(但不支持括号)存在优先级 界面简单,清晰美观,能实现基本运算,加、减、乘、除
    • Android:安卓开发
      安卓 100% 来自 Ramón Invarato Menéndez 的 Android 书籍 100% 的代码。 对于 100% 免费下载 Android 图书: : 如果您认为我们的工作值得,您可以通过以下方式向我们捐款: :
    • owncloud安卓客户端 Android
      android-master.zip是owncloud安卓项目源代码,前两个是该项目依赖的库文件 关于Android account介绍,我的博文有介绍:http://blog.sina.com.cn/s/blog_91d097fb0102vikc.html">本压缩包包括了ActionBarSherlock-...
    • Android安卓项目
      Android Android Android
    • Android:安卓应用
      安卓 安卓应用 安卓应用程序库 如果您想使用其中一些应用程序,请检查它是否使用任何依赖项,例如 google play 服务或其他一些库(例如 Volley);)
    • android安卓 protobuf
      android客户端与服务器间通信,消息传递。
    • android安卓移动体感源码
      安卓移动体感的案例源码,体感游戏时一种通过肢体动作变化来进行操作的新型电子游戏。Android移动体感包括体感游戏功能但不局限于游戏,而是将体感应用到大部分的应用程序中,对PC上的普通程序也能进行体感控制。该...
    • Android安卓手机词典
      安卓手机词典,具有查询单词、生词本、巩固训练等功能,具有与数据库的关联功能,适合初学者对代码分析,学习Android功能。
    • 安卓Android源码
      超级实用的安卓源码