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 远程视频监控程序源码.rar
共67个文件
class:40个
java:14个
xml:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 23 浏览量
2023-04-30
16:47:34
上传
评论
收藏 270KB RAR 举报
温馨提示
Android程序研发源码Android 远程视频监控程序源码.rar
资源推荐
资源详情
资源评论
收起资源包目录
Android程序研发源码Android 远程视频监控程序源码.rar (67个子文件)
CamMonitor
.classpath 280B
assets
src
com
xmobileapp
cammonitor
CamMonitorConfigActivity.java 5KB
core
CameraSource.java 2KB
BitmapCamera.java 1KB
SocketCamera.java 5KB
HttpCamera.java 3KB
ServerAct.java 5KB
view
CamMonitorClient.java 6KB
CamMonitorView.java 6KB
util
MessageListener.java 122B
DatabaseHelper.java 7KB
EditDialog.java 2KB
ActivtyUtil.java 728B
config
CamMonitorParameter.java 2KB
res
values
strings.xml 2KB
layout
main.xml 2KB
server.xml 2KB
add.xml 4KB
drawable
icon.png 3KB
bin
resources.ap_ 13KB
CamMonitor.apk 32KB
classes.dex 37KB
com
xmobileapp
cammonitor
CamMonitorView.class 3KB
CamMonitorConfigActivity.class 6KB
CamMonitorView$CamMonitorThread.class 3KB
CamMonitorConfigActivity$4.class 906B
ServerAct$3.class 1KB
R$string.class 1KB
R$layout.class 472B
ServerAct$2.class 1KB
CamMonitorClient$4$1.class 2KB
R$id.class 2KB
ServerAct$DownloadThread.class 1KB
core
SocketCamera.class 5KB
CameraSource.class 410B
BitmapCamera.class 2KB
HttpCamera.class 4KB
view
R$attr.class 361B
CamMonitorClient$4.class 3KB
ServerAct.class 6KB
CamMonitorClient$2.class 1KB
CamMonitorConfigActivity$3.class 2KB
ServerAct$3$1.class 2KB
R$drawable.class 421B
ServerAct$1.class 971B
CamMonitorClient$3.class 2KB
ServerAct$5.class 1KB
CamMonitorClient$4$2.class 919B
CamMonitorClient.class 4KB
R.class 580B
util
EditDialog.class 3KB
DatabaseHelper$Helper.class 2KB
MessageListener.class 190B
ActivtyUtil$1.class 857B
ActivtyUtil.class 2KB
DatabaseHelper.class 7KB
EditDialog$OnDataSetListener.class 292B
CamMonitorConfigActivity$2.class 3KB
config
CamMonitorParameter.class 2KB
CamMonitorConfigActivity$1.class 835B
CamMonitorClient$1.class 2KB
ServerAct$4.class 830B
default.properties 364B
.project 846B
pc端程序.exe 344KB
AndroidManifest.xml 916B
gen
com
xmobileapp
cammonitor
R.java 4KB
共 67 条
- 1
资源评论
- qq_354589022023-06-01非常有用的资源,可以直接使用,对我很有用,果断支持!
HappyGirl快乐女孩
- 粉丝: 1w+
- 资源: 4160
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 3122080306 邹子轩 实验报告二.docx
- 基于STM32 NUCLEO板设计彩色LED照明灯(纯cubeMX开发)(大赛作品,文档完整,可直接运行)
- 发那科工业机器人保养大全
- Sphere.h
- REMD固有时间尺度分解信号分量可视化(Matlab完整源码和数据)
- 嵌入式系统双单片机STC89C52+STC15W104多功能学习板电路图可扩展 适用于单片机初学者和教学
- 基于STM32蓝牙控制小车系统设计(硬件+源代码+论文)大赛作品
- XILINXFPGA源码基于Spartan3火龙刀系列FPGA开发板VGA测试例程
- Java聊天室的设计与实现【尚学堂·百战程序员】
- python中matplotlib教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功