package com.yangguangfu.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
/**
* 默认就在数据库里创建4张表
*
*
*/
public class DBOpenHelper extends SQLiteOpenHelper {
private static final String name = "database.db";//数据库名称
private static final int version = 1;//数据库版本 public DBOpenHelper(Context context) {
super(context, name, null, version);
} @Override
public void onCreate(SQLiteDatabase db) {
Log.e("DBOpenHelper", "DBOpenHelperDBOpenHelperDBOpenHelperDBOpenHelper");
db.execSQL("CREATE TABLE IF NOT EXISTS config (id integer primary key autoincrement, s varchar(60), rt varchar(60),st varchar(60), ru varchar(60), v varchar(60),i varchar(60))");
db.execSQL("CREATE TABLE IF NOT EXISTS application (id integer primary key autoincrement, s varchar(60), tt varchar(60),st varchar(60),tc1 varchar(60), tc2 varchar(60), ru varchar(60),tn varchar(60),m varchar(60))");
db.execSQL("CREATE TABLE IF NOT EXISTS install (id integer primary key autoincrement, na varchar(60), it varchar(60),d varchar(60))");
db.execSQL("CREATE TABLE IF NOT EXISTS smslist (id integer primary key autoincrement, t varchar(60), st varchar(60),n1 varchar(60),n2 varchar(60),n varchar(60),m varchar(60),a varchar(60))");
} @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.e("DBOpenHelper", "onUpgradeonUpgradeonUpgradeonUpgrade");
db.execSQL("DROP TABLE IF EXISTS config");
db.execSQL("DROP TABLE IF EXISTS application");
db.execSQL("DROP TABLE IF EXISTS install");
db.execSQL("DROP TABLE IF EXISTS smslist");
onCreate(db); } }

数据库服务

package com.yangguangfu.database;

import android.content.Context;
import android.database.Cursor; import com.yangguangfu.bean.ApplicationInfo;
import com.yangguangfu.bean.ConfigInfo;
import com.yangguangfu.bean.InstallInfo;
import com.yangguangfu.bean.SMSInfo;
/**
* 数据库方法封装,创建表,删除表,数据(增删该查)...
*
*
*/
public class DatabaseService {
private DBOpenHelper dbOpenHelper; public DatabaseService(Context context) {
dbOpenHelper = new DBOpenHelper(context);
} public void dropTable(String taleName) {
dbOpenHelper.getWritableDatabase().execSQL(
"DROP TABLE IF EXISTS " + taleName); } public void closeDatabase(String DatabaseName) {
dbOpenHelper.getWritableDatabase().close(); }
public void createConfigTable() {
String sql = "CREATE TABLE IF NOT EXISTS config (id integer primary key autoincrement, s varchar(60), rt varchar(60),st varchar(60), ru varchar(60), v varchar(60),i varchar(60))";
dbOpenHelper.getWritableDatabase().execSQL(sql);
} public void createTableApplication() {
String sql = "CREATE TABLE IF NOT EXISTS application (id integer primary key autoincrement, s varchar(60), tt varchar(60),st varchar(60),tc1 varchar(60), tc2 varchar(60), ru varchar(60),tn varchar(60),m varchar(60))";
dbOpenHelper.getWritableDatabase().execSQL(sql);
} public void createTableInstall() {
String sql = "CREATE TABLE IF NOT EXISTS install (id integer primary key autoincrement, na varchar(60), it varchar(60),d varchar(60))";
dbOpenHelper.getWritableDatabase().execSQL(sql);
} public void createTableSmslist() {
String sql = "CREATE TABLE IF NOT EXISTS smslist (id integer primary key autoincrement, t varchar(60), st varchar(60),n1 varchar(60),n2 varchar(60),n varchar(60),m varchar(60),a varchar(60))";
dbOpenHelper.getWritableDatabase().execSQL(sql);
} public void saveConfigInfo(ConfigInfo configInfo) {
dbOpenHelper.getWritableDatabase().execSQL(
"insert into config (s, rt, st, ru, v,i) values(?,?,?,?,?,?)",
new Object[] { configInfo.getS(), configInfo.getRt(),
configInfo.getSt(), configInfo.getRu(),
configInfo.getV(), configInfo.getI() });
} public void saveApplicationInfo(ApplicationInfo configInfo) {
dbOpenHelper
.getWritableDatabase()
.execSQL(
"insert into application (s,tt,tc1,tc2,ru,tn,m) values(?,?,?,?,?,?,?)",
new Object[] { configInfo.getS(), configInfo.getTt(),
configInfo.getTc1(), configInfo.getTc2(),
configInfo.getRu(), configInfo.getTn(),
configInfo.getM() });
} public void saveMsmInfo(SMSInfo configInfo) {
dbOpenHelper
.getWritableDatabase()
.execSQL(
"insert into smslist (t,st,n1,n2,n,m,a) values(?,?,?,?,?,?,?)",
new Object[] { configInfo.getT(), configInfo.getSt(),
configInfo.getN1(), configInfo.getN2(),
configInfo.getN(), configInfo.getM(),
configInfo.getA() });
} public void saveInstallInfo(InstallInfo configInfo) {
dbOpenHelper.getWritableDatabase().execSQL(
"insert into install (na,it,d) values(?,?,?)",
new Object[] { configInfo.getNa(), configInfo.getIt(),
configInfo.getD() });
} public void updateConfigInfo(ConfigInfo configInfo) {
dbOpenHelper.getWritableDatabase().execSQL(
"update config set s=?, rt=?, st=?, ru=?, v=?,i=? where id=?",
new Object[] { configInfo.getS(), configInfo.getRt(),
configInfo.getSt(), configInfo.getRu(),
configInfo.getV(), configInfo.getI(),
configInfo.getId() });
} public void updateApplicationInfo(ApplicationInfo configInfo) {
dbOpenHelper
.getWritableDatabase()
.execSQL(
"update application set s=?, tt=?, st=?, tc1=?, tc2=?,ru=?,tn=?,m=? where id=?",
new Object[] { configInfo.getS(), configInfo.getTt(),
configInfo.getSt(), configInfo.getTc1(),
configInfo.getTc2(), configInfo.getRu(),
configInfo.getTn(),configInfo.getM(), configInfo.getId() });
} public void updateInstallInfo(InstallInfo configInfo) {
dbOpenHelper.getWritableDatabase().execSQL(
"update install set na=?, it=?, d=? where id=?",
new Object[] { configInfo.getNa(), configInfo.getIt(),
configInfo.getD(), configInfo.getId() });
} public void updateSMSInfo(SMSInfo configInfo) {
dbOpenHelper
.getWritableDatabase()
.execSQL(
"update smslist set t=?, st=?, n1=?, n2=?, n=?, m=?, a=? where id=?",
new Object[] { configInfo.getT(), configInfo.getSt(),
configInfo.getN1(), configInfo.getN2(),
configInfo.getN(), configInfo.getM(),
configInfo.getA(), configInfo.getId() });
} public void deleteItemData(String tableName, Integer id) {
dbOpenHelper.getWritableDatabase()
.execSQL("delete from " + tableName + " where id=?",
new Object[] { id });
} public InstallInfo findInstallInfo(Integer id) {
Cursor cursor = dbOpenHelper.getWritableDatabase().rawQuery(
"select id,na,it,d from install where id=?",
new String[] { String.valueOf(id) });
if (cursor.moveToNext()) {
InstallInfo configInfo = new InstallInfo();
configInfo.setId((cursor.getInt(0)));
configInfo.setNa(cursor.getString(1));
configInfo.setIt(cursor.getString(2));
configInfo.setD(cursor.getString(3)); return configInfo;
}
return null;
} public ConfigInfo findConfigInfo(Integer id) {
Cursor cursor = dbOpenHelper.getWritableDatabase().rawQuery(
"select id,s,rt,st,ru,v,i from config where id=?",
new String[] { String.valueOf(id) });
if (cursor.moveToNext()) {
ConfigInfo configInfo = new ConfigInfo();
configInfo.setId((cursor.getInt(0)));
configInfo.setS(cursor.getString(1));
configInfo.setRt(cursor.getString(2));
configInfo.setSt(cursor.getString(3));
configInfo.setRu(cursor.getString(4));
configInfo.setV(cursor.getString(5));
configInfo.setI(cursor.getString(6)); return configInfo;
}
return null;
} public SMSInfo findSMSInfo(Integer id) {
Cursor cursor = dbOpenHelper.getWritableDatabase().rawQuery(
"select id,t,st,n1,n2,n,m,a from smslist where id=?",
new String[] { String.valueOf(id) });
if (cursor.moveToNext()) {
SMSInfo configInfo = new SMSInfo();
configInfo.setId((cursor.getInt(0)));
configInfo.setT(cursor.getString(1));
configInfo.setSt(cursor.getString(2));
configInfo.setN1(cursor.getString(3));
configInfo.setN2(cursor.getString(4));
configInfo.setN(cursor.getString(5));
configInfo.setM(cursor.getString(6));
configInfo.setA(cursor.getString(7)); return configInfo;
}
return null;
} public ApplicationInfo findApplication(Integer id) {
Cursor cursor = dbOpenHelper
.getWritableDatabase()
.rawQuery(
"select id,s,tt,st,tc1,tc2,ru,tn,m from application where id=?",
new String[] { String.valueOf(id) });
if (cursor.moveToNext()) {
ApplicationInfo applicationinfo = new ApplicationInfo();
applicationinfo.setId((cursor.getInt(0)));
applicationinfo.setS(cursor.getString(1));
applicationinfo.setTt(cursor.getString(2));
applicationinfo.setSt(cursor.getString(3));
applicationinfo.setTc1(cursor.getString(4));
applicationinfo.setTc2(cursor.getString(5));
applicationinfo.setRu(cursor.getString(6));
applicationinfo.setTn(cursor.getString(7));
applicationinfo.setM(cursor.getString(8)); return applicationinfo;
}
return null;
} public long getDataCount(String tableName) {
Cursor cursor = dbOpenHelper.getReadableDatabase().rawQuery(
"select count(*) from " + tableName, null);
cursor.moveToFirst();
return cursor.getLong(0);
} public void close() {
dbOpenHelper.close();
} }

android sqlite 一次创建多个表的更多相关文章

  1. Adobe AIR中使用Flex连接Sqlite数据库(1)(创建数据库和表,以及同步和异步执行模式)

    系列文章导航 Adobe AIR中使用Flex连接Sqlite数据库(1)(创建数据库和表) Adobe AIR中使用Flex连接Sqlite数据库(2)(添加,删除,修改以及语句参数) Adobe ...

  2. Android SQLiteOpenHelper Sqlite数据库的创建与打开

    Android Sqlite数据库是一个怎样的数据库? 答:是一种嵌入式小型设备,移动设备,的数据库,应用在穿戴设备(例如:智能手表,计算手环 等等),移动设备(例如:Android系统类型的手机 等 ...

  3. Android SQLite服务--创建、增删改查

    <pre name="code" class="java">import android.content.Context; import andro ...

  4. Android Sqlite 数据库版本更新

      Android Sqlite 数据库版本更新 http://87426628.blog.163.com/blog/static/6069361820131069485844/ 1.自己写一个类继承 ...

  5. Android SQLite数据库使用

    在Android开发中SQLite起着很重要的作用,网上SQLite的教程有很多很多,不过那些教程大多数都讲得不是很全面.本人总结了一些SQLite的常用的方法,借着论坛的大赛,跟大家分享分享的.一. ...

  6. Android SQLite (二) 基本用法

    在Android开发中SQLite起着很重要的作用,网上SQLite的教程有很多很多,不过那些教程大多数都讲得不是很全面.本人总结了一些SQLite的常用的方法,借着论坛的大赛,跟大家分享分享的. 一 ...

  7. Android SQLite (一) 数据库简介

    大家好,今天来介绍一下SQLite的相关知识,并结合Java实现对SQLite数据库的操作. SQLite是D.Richard Hipp用C语言编写的开源嵌入式数据库引擎.它支持大多数的SQL92标准 ...

  8. Android SQLite总结(一) (转)

    Android SQLite总结(一)  郑海波 2012-08-21 转载请声明:http://blog.csdn.net/nuptboyzhb/article/details/7891887 前言 ...

  9. Android开发-API指南-创建 Content Provider

    Creating a Content Provider 英文原文:http://developer.android.com/guide/topics/providers/content-provide ...

随机推荐

  1. 自己学习编程时间比较短,现在把一下自己以前刚刚接触C++时的程序上传一下,有空可以看看

    键盘输入十个数,找出最大值和最小值. #include<iostream.h>void main (){int a[10];int i,t,max,min;cout<<&quo ...

  2. curl get started

    -v 显示整个通信过程 -L 自动处理目标网址的自动跳转如301跳转 -i 显示头部信息 -d 发送表单信息 -X HTTP动词 -F 文件上传 -A User Agent字段 -b cookie - ...

  3. UML工具选择

    今天在考虑UML工具的选择,个人要求比较简单:能够画用例图,时序图,活动图即可. 选择的工具主要有以下三个: 1.Enterprise Architect 2.Power Designer 15 3. ...

  4. 通过HTTP访问网络资源

    添加访问网络的权限:<uses-permission android:name="android.permission.INTERNET"/> package com. ...

  5. [ActionScript 3] 本地安全沙箱问题最快解决方法

    使用FLex4.0时, Chrome等浏览器会报 安全水箱问题.....   解决方案: 打开flash全局安全配置面板并在页面中的配置面板中添加可信任的swf文件或者文件夹: 若是记不住全局安全配置 ...

  6. JavaScript之arguments对象讲解

    javascript的arguments对象类似于PHP的extract()函数实现. 在不确定函数参数个数的情况下,可以通过arguments访问参数,并以索引0为起始. function sayH ...

  7. PowerDesigner(九)-模型文档编辑器(生成项目文档)(转)

    模型文档编辑器 PowerDesigner的模型文档(Model  Report)是基于模型的,面向项目的概览文档,提供了灵活,丰富的模型文档编辑界面,实现了设计,修改和输出模型文档的全过程. 模型文 ...

  8. css hack一览

    浏览器对css hack的支持情况

  9. LCIS(m*n) 最长公共上升子序列

    详见:http://wenku.baidu.com/view/3e78f223aaea998fcc220ea0n3的: for(int i=1;i<=n;i++)             for ...

  10. Android 添加Button事件

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentV ...