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;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
2021-安全保密-Android 远程视频监控程序源码.zip
共68个文件
class:40个
java:14个
xml:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 63 浏览量
2022-03-02
10:16:26
上传
评论
收藏 333KB ZIP 举报
温馨提示
2021-安全保密-Android 远程视频监控程序源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
2021-安全保密-Android 远程视频监控程序源码.zip (68个子文件)
Android 远程视频监控程序源码
Android 远程视频监控程序源码
bin
classes.dex 37KB
com
xmobileapp
cammonitor
CamMonitorClient$1.class 2KB
CamMonitorClient.class 4KB
CamMonitorConfigActivity$1.class 835B
CamMonitorClient$4$1.class 2KB
CamMonitorView.class 3KB
core
HttpCamera.class 4KB
CameraSource.class 410B
BitmapCamera.class 2KB
SocketCamera.class 5KB
config
CamMonitorParameter.class 2KB
CamMonitorClient$4$2.class 919B
CamMonitorConfigActivity$3.class 2KB
ServerAct.class 6KB
R$layout.class 472B
R$id.class 2KB
R$drawable.class 421B
view
R$attr.class 361B
CamMonitorClient$2.class 1KB
R.class 580B
ServerAct$3$1.class 2KB
ServerAct$3.class 1KB
ServerAct$1.class 971B
ServerAct$4.class 830B
CamMonitorConfigActivity.class 6KB
ServerAct$2.class 1KB
CamMonitorClient$3.class 2KB
R$string.class 1KB
ServerAct$5.class 1KB
CamMonitorView$CamMonitorThread.class 3KB
CamMonitorClient$4.class 3KB
util
ActivtyUtil$1.class 857B
MessageListener.class 190B
DatabaseHelper.class 7KB
EditDialog$OnDataSetListener.class 292B
EditDialog.class 3KB
ActivtyUtil.class 2KB
DatabaseHelper$Helper.class 2KB
ServerAct$DownloadThread.class 1KB
CamMonitorConfigActivity$4.class 906B
CamMonitorConfigActivity$2.class 3KB
CamMonitor.apk 32KB
resources.ap_ 13KB
res
drawable
icon.png 3KB
values
strings.xml 2KB
layout
add.xml 4KB
main.xml 2KB
server.xml 2KB
assets
default.properties 364B
gen
com
xmobileapp
cammonitor
R.java 4KB
src
com
xmobileapp
cammonitor
core
CameraSource.java 2KB
HttpCamera.java 3KB
SocketCamera.java 5KB
BitmapCamera.java 1KB
config
CamMonitorParameter.java 2KB
ServerAct.java 5KB
CamMonitorView.java 6KB
view
CamMonitorClient.java 6KB
util
DatabaseHelper.java 7KB
MessageListener.java 122B
ActivtyUtil.java 728B
EditDialog.java 2KB
CamMonitorConfigActivity.java 5KB
.project 846B
.classpath 280B
pc端程序.exe 344KB
AndroidManifest.xml 916B
1_121023101159_1.png 23KB
共 68 条
- 1
资源评论
智慧方案文库
- 粉丝: 1769
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功