昨天完成了数据表的增加和删除
那今天完成以下展示吧
package zzm.org.kebiaojIEmian;import androID.app.Application;import androID.content.ContentValues;import androID.content.Context;import androID.database.Cursor;import androID.database.sqlite.sqliteDatabase;import androID.database.sqlite.sqliteOpenHelper;public class DataBase extends sqliteOpenHelper { private final static String DB_name="myBase"; private static String[] TB_name= new String[]{"Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun"}; public final static String ID="_ID"; public final static String CLASS="classes"; public final static String LOCA="location"; public final static String TEACHER="teacher"; public final static String ZHOUSHU="zhoushu"; public final static String JIESHU="jIEshu"; public final static String TIME1="time1"; public final static String TIME2="time2"; public final static String WHICH="which"; public DataBase(Context context){ super(context,DB_name,null,1); } @OverrIDe public voID onCreate(sqliteDatabase db) { for(int i=0;i<7;i++){ String sql="CREATE table "+TB_name[i]+" (_ID INTEGER primary key autoincrement,classes varchar(70),location varchar(70)," + "teacher varchar(70),zhoushu varchar(70),time1 varchar(70),time2 varchar(70),jIEshu varchar(70),which varchar(70))"; db.execsql(sql); } } @OverrIDe public voID onUpgrade(sqliteDatabase db, int oLeversion, int newVersion) { for(int i=0;i<7;i++){ String sql="DROP table IF EXISTS "+TB_name[i]; db.execsql(sql); } onCreate(db); } public Cursor select(int i){ sqliteDatabase db=DataBase.this.getReadableDatabase(); Cursor cursor=db.query(TB_name[i],null,null,null,null,null,null); return cursor; } public long insert(int i,String cla,String loca,String tea,String zhou,String jIE,String time1,String time2,String which){ sqliteDatabase db=DataBase.this.getWritableDatabase(); ContentValues cv=new ContentValues(); cv.put(CLASS,cla); cv.put(LOCA, loca); cv.put(TEACHER,tea); cv.put(ZHOUSHU,zhou); cv.put(JIESHU,jIE); cv.put(TIME1,time1); cv.put(TIME2,time2); cv.put(WHICH,which); long row=db.insert(TB_name[i],null,cv); return row; } public voID update(int i,int _ID,String cla,String loca,String tea,String zhou,String jIE,String time1,String time2,String which){ sqliteDatabase db=DataBase.this.getWritableDatabase(); String where="_ID = ?"; String[] whereValues={Integer.toString(_ID)}; ContentValues cv=new ContentValues(); if(!cla.equals("")) cv.put(CLASS,cla); if(!loca.equals("")) cv.put(LOCA, loca); if(!tea.equals("")) cv.put(TEACHER,tea); if(!zhou.equals("")) cv.put(ZHOUSHU,zhou); if(!jIE.equals("")) cv.put(JIESHU,jIE); if(!time1.equals("")) cv.put(TIME1,time1); if(!time2.equals("")) cv.put(TIME2,time2); if(!which.equals("")) cv.put(WHICH,which); db.update(TB_name[i], cv, where, whereValues); } public voID deleteData(int i,int _ID){ sqliteDatabase db=DataBase.this.getWritableDatabase(); String where="_ID = ?"; String[] whereValues={Integer.toString(_ID)}; ContentValues cv=new ContentValues(); cv.put("classes",""); cv.put("location",""); cv.put("teacher",""); cv.put("zhoushu",""); cv.put("jIEshu",""); cv.put("time1",""); cv.put("time2",""); cv.put("which",""); db.update(TB_name[i], cv, where, whereValues); } public voID delete(int i,int _ID){ sqliteDatabase db=this.getWritableDatabase(); String where="_ID = ?"; String[] whereValues={Integer.toString(_ID)}; db.delete(TB_name[i], where, whereValues); } public voID createtable(int j){ for(int i=1;i<=12;i++) insert(j,"", "", "","","","","",""); }}
总结
以上是内存溢出为你收集整理的4.22日软件开发日记:今天我干了什么?全部内容,希望文章能够帮你解决4.22日软件开发日记:今天我干了什么?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)