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的视频传输
共109个文件
class:80个
java:14个
xml:5个
需积分: 9 18 下载量 38 浏览量
2015-03-04
14:27:51
上传
评论 5
收藏 168KB RAR 举报
温馨提示
视频截图.rar 视频监控源码-android.rar 视频监控PC端程序.rar 可用基于Socket的Android手机视频实时传输.rar 图片相似度服务源码c# -ImgComparatorService.rar
资源推荐
资源详情
资源评论
收起资源包目录
基于android的视频传输 (109个子文件)
resources.ap_ 13KB
CamMonitor.apk 32KB
DatabaseHelper.class 7KB
DatabaseHelper.class 7KB
CamMonitorConfigActivity.class 6KB
CamMonitorConfigActivity.class 6KB
ServerAct.class 6KB
ServerAct.class 6KB
SocketCamera.class 5KB
SocketCamera.class 5KB
HttpCamera.class 4KB
HttpCamera.class 4KB
CamMonitorClient.class 4KB
CamMonitorClient.class 4KB
CamMonitorView$CamMonitorThread.class 3KB
CamMonitorView$CamMonitorThread.class 3KB
CamMonitorConfigActivity$2.class 3KB
CamMonitorConfigActivity$2.class 3KB
EditDialog.class 3KB
EditDialog.class 3KB
CamMonitorClient$4.class 3KB
CamMonitorClient$4.class 3KB
CamMonitorView.class 3KB
CamMonitorView.class 3KB
CamMonitorParameter.class 2KB
CamMonitorParameter.class 2KB
CamMonitorConfigActivity$3.class 2KB
CamMonitorConfigActivity$3.class 2KB
CamMonitorClient$3.class 2KB
CamMonitorClient$3.class 2KB
CamMonitorClient$1.class 2KB
CamMonitorClient$1.class 2KB
BitmapCamera.class 2KB
BitmapCamera.class 2KB
CamMonitorClient$4$1.class 2KB
CamMonitorClient$4$1.class 2KB
R$id.class 2KB
R$id.class 2KB
DatabaseHelper$Helper.class 2KB
DatabaseHelper$Helper.class 2KB
ActivtyUtil.class 2KB
ActivtyUtil.class 2KB
ServerAct$3$1.class 2KB
ServerAct$3$1.class 2KB
ServerAct$DownloadThread.class 1KB
ServerAct$DownloadThread.class 1KB
ServerAct$5.class 1KB
ServerAct$5.class 1KB
R$string.class 1KB
R$string.class 1KB
ServerAct$3.class 1KB
ServerAct$3.class 1KB
CamMonitorClient$2.class 1KB
CamMonitorClient$2.class 1KB
ServerAct$2.class 1KB
ServerAct$2.class 1KB
ServerAct$1.class 971B
ServerAct$1.class 971B
CamMonitorClient$4$2.class 919B
CamMonitorClient$4$2.class 919B
CamMonitorConfigActivity$4.class 906B
CamMonitorConfigActivity$4.class 906B
ActivtyUtil$1.class 857B
ActivtyUtil$1.class 857B
CamMonitorConfigActivity$1.class 835B
CamMonitorConfigActivity$1.class 835B
ServerAct$4.class 830B
ServerAct$4.class 830B
R.class 580B
R.class 580B
R$layout.class 472B
R$layout.class 472B
R$drawable.class 421B
R$drawable.class 421B
CameraSource.class 410B
CameraSource.class 410B
R$attr.class 361B
R$attr.class 361B
EditDialog$OnDataSetListener.class 292B
EditDialog$OnDataSetListener.class 292B
MessageListener.class 190B
MessageListener.class 190B
.classpath 288B
Thumbs.db 4KB
classes.dex 37KB
DatabaseHelper.java 7KB
CamMonitorView.java 6KB
CamMonitorClient.java 6KB
CamMonitorConfigActivity.java 5KB
ServerAct.java 5KB
SocketCamera.java 5KB
R.java 4KB
HttpCamera.java 3KB
CamMonitorParameter.java 2KB
EditDialog.java 2KB
CameraSource.java 2KB
BitmapCamera.java 1KB
ActivtyUtil.java 728B
MessageListener.java 122B
icon.png 3KB
共 109 条
- 1
- 2
资源评论
duyang199
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功