Android SQLite的创建

来源:互联网 发布:软件杯 编辑:程序博客网 时间:2024/05/22 03:12

     这是在实际工作最近遇到问题,自己对SQLite的心得 欢迎提问

1.      主体包

2.      xxxxx.Vo 序列化(list显示数据 看项布局需要的项属性)

   显示Adapter的各种属性例如


显示属性就是有Name price(外加id是数据库的序号递增用于删除查找等功能)

 

3.      xxxxx.util 创建数据库和表

  

  SystemCall 用来定义数据库用的字符窜

  public final static String DB_NAME="product_collect";

  publicfinalstaticStringDB_TAB="product";

   public final static int VER_BASE=1;

  SqlHelp用来继承SQLiteOpenHelper

    //表示   //创建数据库

    publicSqlHelp(Context context, String name,

            int version) {

        super(context, name,null, version);    }

 

    @Override  //创建表

    public void onCreate(SQLiteDatabase db) {

       

        db.execSQL("create table if not exists "

                 +SystemCall.DB_TAB

                 +"(_idinteger primary key autoincrement,product_name varchar(12),product_pricevarchar(12))"

                );

 

    }

 

    @Override  //更新版本

    public void onUpgrade(SQLiteDatabase db,int oldVersion, int newVersion) {

    }

     //注意红色的语句,这里需要实例化help对象进行数据库的创建

4.      xxxxx.dao 对数据库操作(增删查改)(连接)

     SQLiteDatabase db;

    SqlHelp help;

    Context context;

public Db(Context context) {super();

     this.context= context;

     help = new SqlHelp(context,SystemCall.DB_NAME, SystemCall.VER_BASE);

}

      //注意这个是帮助类,控制listView每一项

5.      xxxxx.adapter

    ViewHolder h;

    Context context;

    List<Good> list;

    public MyAdapter(Contextcontext, List<Good> list) {

        super();

        this.context = context;

        this.list = list;

    }

0 0
原创粉丝点击