例题数据库
来源:互联网 发布:无3c被淘宝下架了宝贝 编辑:程序博客网 时间:2024/05/16 10:35
package com.bawei;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import bean.Items;
import bean.Student;
import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.widget.ListView;
public class ShowMainActivity extends Activity {
private ListView lv;
private SQLiteDatabase database;
List list=new ArrayList();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_main);
lv=(ListView) findViewById(R.id.lv);
//得到解析文件
String str=Environment.getExternalStorageDirectory()+”/”+”cardata.json”;
try {
File file=new File(str);
FileReader reader=new FileReader(file);
//解析
Gson gson=new Gson();
Student student = gson.fromJson(reader, Student.class);
List items = student.getData().getItems();
//添加到数据库
MySQLiteDatabase mySQLiteDatabase = new MySQLiteDatabase(ShowMainActivity.this);
//得到数据库
database=mySQLiteDatabase.getReadableDatabase();
for (Items items2 : items) {
ContentValues values=new ContentValues();
values.put(“brand”, items2.getBrand());
values.put(“name”, items2.getName());
values.put(“price”, items2.getPrice());
database.insert(“student”, null, values);
} //关闭数据库 database.close(); reader.close(); //查找 database=mySQLiteDatabase.getReadableDatabase(); Cursor cursor=database.query("student", new String[]{"brand","name","price"}, null, null, null,null, null); while (cursor.moveToNext()) { String brand=cursor.getString(cursor.getColumnIndex("brand")); String name=cursor.getString(cursor.getColumnIndex("name")); String price=cursor.getString(cursor.getColumnIndex("price")); Items tItems3=new Items(); tItems3.setBrand(brand); tItems3.setName(name); tItems3.setPrice(price); list.add(tItems3); } //关闭数据库 database.close(); //适配器 lv.setAdapter(new Mydater(list,ShowMainActivity.this)); } catch (JsonSyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JsonIOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
}
- 例题数据库
- Oracle数据库操作例题
- SQL数据库50例题
- 例题5-9 数据库 UVa1592
- 例题
- 例题
- 例题
- 例题
- vb数据库编程精华例题分享
- 例题5-9 UVA 1592 Database数据库
- 关系数据库规范化(例题解析)
- oracle 数据库 50道经典例题
- 数据库查询语句易错例题整理
- sql server 2005数据库的一些应用例题
- 在MySchool数据库中有俩个表:Student和Score(相关例题)
- SQL数据库面试题以及答案(50例题)
- 紫书章五例题9 数据库 UVA 1592 (map+vector)
- SQL数据库面试题以及答案(50例题)
- 记录友盟分享,第三方登录遇到的坑
- 虚拟化管理平台的选择:开源软件 or 商业软件?
- Android 地理位置定位
- poj 2251 Dungeon Master
- 牛客在线编程(剑指offer)---二维数组中的查找
- 例题数据库
- ecshop二次开发--优惠活动
- winpcap程序员开发包下载
- GCDAsyncSocket不通过服务器进行客户端间直接连接—iOS移动开发
- 剑指Offer_49_把字符串转换成整数
- 【bzoj1066】[SCOI2007]蜥蜴
- ajax/php/javascript实现分页
- Android优化策略
- PHP SPL简介