package com.example.jizhangben; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class CostDB extends SQLiteOpenHelper { public static final String TABLE_NAME = "costs"; public static final String MONEY = "money"; public static final String DATE = "date"; public static final String TITLE = "title"; public CostDB(Context context) { super(context, "costs1", null, 1); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table if not exists "+ TABLE_NAME +"("+ "id integer primary key, "+ "title varchar, "+ "date varchar, "+ "money varchar)"); } public void insertCost(costBean costBean1) { SQLiteDatabase database=getWritableDatabase(); ContentValues cv=new ContentValues(); cv.put(TITLE,costBean1.costTitle); cv.put(DATE,costBean1.costDate); cv.put(MONEY,costBean1.costMoney); database.insert("TABLE_NAME",null,cv); } public Cursor getAllCostData(){ SQLiteDatabase database = getReadableDatabase(); return database.query("TABLE_NAME",null,null,null,null,null,null); } public void deleteAllData(){ SQLiteDatabase database=getWritableDatabase(); database.delete("TABLE_NAME",null,null); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } }