public class MySqlHelp extends SQLiteOpenHelper { public MySqlHelp(Context context) { super(context, "news", null, 1); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table news(id integer primary key autoincrement,title text,thumbnail_pic_s text,thumbnail_pic_s02 text,thumbnail_pic_s03 text)"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } //使用public class f1sqlManger { SQLiteDatabase sd; private Context con; public f1sqlManger(Context con) { // TODO Auto-generated constructor stub sd=new MySqlHelp(con).getWritableDatabase(); } public void insert(List<HotBean.ResultBean.DataBean> teach){ sd.beginTransaction(); try { for (int i = 0; i <teach.size(); i++) { ContentValues cv=new ContentValues(); HotBean.ResultBean.DataBean tb=teach.get(i); cv.put("title",tb.getTitle()); cv.put("thumbnail_pic_s03",tb.getTitle()); cv.put("thumbnail_pic_s02",tb.getTitle()); cv.put("thumbnail_pic_s",tb.getTitle()); sd.insert("news", null, cv); } sd.setTransactionSuccessful(); } finally{ sd.endTransaction(); } } public List<HotBean.ResultBean.DataBean> selest_List(){ List<HotBean.ResultBean.DataBean> lt=new ArrayList<HotBean.ResultBean.DataBean>(); Cursor c=sd.query("news", null, null, null, null, null, null); while(c.moveToNext()){ HotBean.ResultBean.DataBean tbean=new HotBean().new ResultBean().new DataBean(); tbean.title=c.getString(c.getColumnIndex("title")); tbean.thumbnail_pic_s=c.getString(c.getColumnIndex("thumbnail_pic_s")); tbean.thumbnail_pic_s02=c.getString(c.getColumnIndex("thumbnail_pic_s02")); tbean.thumbnail_pic_s03=c.getString(c.getColumnIndex("thumbnail_pic_s03")); lt.add(tbean); } return lt; } }
新闻数据库
最新推荐文章于 2024-06-26 10:39:24 发布