MyDataBase
package com.activity.db; import com.acyivity.Utils.Utils; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class MyDataBase extends SQLiteOpenHelper { public MyDataBase(Context context) { super(context, "gourmetMealshujuku.db", null, 1); } @Override public void onCreate(SQLiteDatabase db) { /** * 版本号 */ db.execSQL("create table " + Utils.BAN_BEN_HAO + "(_id integer primary key autoincrement," + "banben,"// 版本 + "beizhu"// 备注 + ")"); /** * 菜单表 */ db.execSQL("create table " + Utils.CAI_DAN + "(_id integer primary key autoincrement," + "dish_id," + "dish_class," + "dish_name," + "image," + "price," + "itrInfo," + "dish_num text default 1," + "tejiacai" + "remark)"); /** * 桌子表 */ db.execSQL("create table " + Utils.TABLE + "(_id integer primary key autoincrement," + "table_name,"// 桌子名称 + "table_num," + "table_address," + "waiter_num" + ")"); /** * 订单表 */ db.execSQL("create table " + Utils.ORDER + "(_id integer primary key autoincrement," + "dish_id," + "dish_name," + "dish_class,dish_num,price,remark)"); /** * 创建表 表名:流水账号 */ db.execSQL("create table " + Utils.LIU_SHUI_HAO + "(_id integer primary key autoincrement,liushuihao,remark)"); /** * 创建表 表名:下单表 用于结账时和下单时 列名:_id、用户名、等级、流水账号、桌号、序号、菜名、单价、数量、价格 */ db.execSQL("create table " + Utils.XIA_DAN + "(_id integer primary key autoincrement, username, grade, liushuihao, table_num,xuhao,dish_name,price,dish_num,total_price)"); /** * 凉菜表 */ db.execSQL("create table " + Utils.COLD_DISH + "(_id integer primary key autoincrement," + "dish_id," + "dish_class," + "dish_name," + "image," + "price," + "itrInfo," + "dish_num text default 1," + "tejiacai" + "remark)"); /** * 热菜表 */ db.execSQL("create table " + Utils.HOT_DISH + "(_id integer primary key autoincrement," + "dish_id," + "dish_class," + "dish_name," + "image," + "price," + "itrInfo," + "dish_num text default 1," + "tejiacai" + "remark)"); /** * 酒类表 */ db.execSQL("create table " + Utils.JIU + "(_id integer primary key autoincrement," + "dish_id," + "dish_class," + "dish_name," + "image," + "price," + "itrInfo," + "dish_num text default 1," + "tejiacai" + "remark)"); /** * 餐具表 */ db.execSQL("create table " + Utils.CAN_JU + "(_id integer primary key autoincrement," + "dish_id," + "dish_class," + "dish_name," + "image," + "price," + "itrInfo," + "dish_num text default 1," + "tejiacai" + "remark)"); /** * 汤类表 */ db.execSQL("create table " + Utils.TANG_LEI + "(_id integer primary key autoincrement," + "dish_id," + "dish_class," + "dish_name," + "image," + "price," + "itrInfo," + "dish_num text default 1," + "tejiacai" + "remark)"); /** * 饮料表 */ db.execSQL("create table " + Utils.YIN_LIAO + "(_id integer primary key autoincrement," + "dish_id," + "dish_class," + "dish_name," + "image," + "price," + "itrInfo," + "dish_num text default 1," + "tejiacai" + "remark)"); /** * 主食表 */ db.execSQL("create table " + Utils.ZHU_SHI + "(_id integer primary key autoincrement," + "dish_id," + "dish_class," + "dish_name," + "image," + "price," + "itrInfo," + "dish_num text default 1," + "tejiacai" + "remark)"); } @Override public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) { // TODO Auto-generated method stub } }
另一种
package com.db; import com.activity.Util.Util; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteDatabase.CursorFactory; public class DBhelper extends SQLiteOpenHelper { public DBhelper(Context context) { super(context, "dish.db", null, 1); } public static DBhelper mInstance = null; @Override public void onCreate(SQLiteDatabase db) { // 菜单表 String sql = "create table " + Util.DB_TABLE_DISH + "(_id integer primary key autoincrement,dish_id,dish_class,dish_name,image,price,itrInfo,dish_num text default 1)"; db.execSQL(sql); // 订单表 String sql1 = "create table " + Util.DB_TABLE_ORDER + "(_id integer primary key autoincrement,order_id,table_num,isaccount,remark)"; db.execSQL(sql1); // 桌子表 String sql2 = "create table " + Util.DB_TABLE_TABLE + "(_id integer primary key autoincrement,table_num,table_name,table_address,table_people)"; db.execSQL(sql2); // 临时订单表 String sql3 = "create table " + Util.DB_TABLE_TEMP_ORDER + "(_id integer primary key autoincrement,table_num,dish_id,order_id,number)"; db.execSQL(sql3); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } public static SQLiteOpenHelper getInstance(Context context, CursorFactory factory) { if(mInstance == null){ mInstance = new DBhelper(context); } return mInstance; } }