android项目小模块

解析:

package com.jxc.db;

import java.util.List;
import com.jxc.bean.Information;
import android.content.ContentValues;
import android.content.Context;

public class DbUtil {
 Context context;
 /**
  * 向菜单表中插入数据
  * @param dishes
  */
 private void saveDish(List<Information> infos) {
  DbHelper hBhelper = new DbHelper(context);
  if (infos != null) {
   for (Information info : infos) {
    ContentValues values = new ContentValues();
    values.put("title", info.getTitle());
    values.put("sender", info.getSender());
    values.put("time", info.getTime());
    values.put("content", info.getContent());
    
    hBhelper.getWritableDatabase().insert("Info", null,
      values);
   }
  }
  hBhelper.close();
 }
 
 /**
  * 从SQLite数据库中删除相应项目
  *
  * @param context
  * @param tableNum
  * @param dishId
  */
 public static void deleteOrderItem(Context context, String title) {
  DbHelper hBhelper = new DbHelper(context);
  hBhelper.getWritableDatabase().delete("Info", "title=?",
    new String[] { title });

  hBhelper.close();
 }
 
// /**
//  * 查询菜单
//  *
//  * @return
//  */
// public List<Dish> getDish() {
//  mdb = new MyDataBase(context);
//  database = mdb.getReadableDatabase();
//
//  Cursor cur = database.query(Utils.CAI_DAN, null, null, null, null,
//    null, null);
//  List<Dish> list = null;
//  if (cur != null) {
//   list = new ArrayList<Dish>();
//   while (cur.moveToNext()) {
//    String id = cur.getString(cur.getColumnIndex("dish_id"));
//    String dish_name = cur.getString(cur
//      .getColumnIndex("dish_name"));
//    int dish_num = cur.getInt(cur.getColumnIndex("dish_num"));
//    String dish_class = cur.getString(cur
//      .getColumnIndex("dish_class"));
//    String imgPath = cur.getString(cur.getColumnIndex("image"));
//    String describe = cur.getString(cur.getColumnIndex("itrInfo"));
//    int price = cur.getInt(cur.getColumnIndex("price"));
//
//    Dish d = new Dish();
//    d.setDish_id(id);
//    d.setDiah_name(dish_name);
//    d.setDish_class(dish_class);
//    d.setDish_num(dish_num);
//    d.setImage(imgPath);
//    d.setItrInfo(describe);
//    d.setPrice(price);
//
//    list.add(d);
//   }
//   database.close();
//   cur.close();
//   mdb.close();
//  }
//
//  return list;
// }
 

// /**
//  * 根据姓名查成绩
//  * @param name
//  * @return
//  */
// public List<Student> queryStudent(String name){
//  SQLiteDatabase db=new DbHelper(context).getReadableDatabase();
//  List<Student> list=null;
//  
//  String sql="select id,name,score from students where name=?";
//  Cursor cur=db.rawQuery(sql, new String[] {name});
//  Student student=new Student();
//  if(cur!=null){
//   list=new ArrayList<Student>();
//   while(cur.moveToNext()){
//    student.setName(cur.getString(1));
//    student.setScore(cur.getString(2));
//    
//    list.add(student);
//   }
//  }
//  return list;
// }
}

 

package com.jxc.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DbHelper extends SQLiteOpenHelper{

 public DbHelper(Context context) {
  super(context, "JXTDB.db", null, 1);
 }

 @Override
 public void onCreate(SQLiteDatabase db) {
  String sql="create table Info(_id primary key autoincrement,title,sender,time,content)";
  db.execSQL(sql);
 }

 @Override
 public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
 }

}

你可能感兴趣的:(android项目小模块)