从json解析中插入数据到sqlite数据库
我想在android数据解析表单中的json数组数据中插入数据到sqLite数据库。 我的代码如下: 1)DBHelperClass - 数据库创建 public class DueAmountDataBHelper extends SQLiteOpenHelper { public DueAmountDataBHelper(Context context) { super(context, "abc.db", null, 1); } @Override public void onCreate(SQLiteDatabase db) { String CREATE_TABLE_PRODUCT_DUE_AMT = "create table due_amt_tab(" + "shopId text primary key, " + "shopName text NOT NULL, " + "teluguName text NOT NULL, " + "place text NOT NULL, " + "dueAmount text NOT NULL " + ")"; db.execSQL(CREATE_TABLE_PRODUCT_DUE_AMT); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } public List<DueAmtDBModel> getShopdata() { List<DueAmtDBModel> data = new ArrayList<>(); SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery("select * from due_amt_tab", null); StringBuffer stringBuffer = new StringBuffer(); DueAmtDBModel dataModel = null; while (cursor.moveToNext()) { dataModel = new DueAmtDBModel(); String shopId, shopName, teluguName, place, dueAmount; shopId = cursor.getString(cursor.getColumnIndexOrThrow("shopId")); shopName = cursor.getString(cursor.getColumnIndexOrThrow("shopName")); teluguName = cursor.getString(cursor.getColumnIndexOrThrow("teluguName")); place = cursor.getString(cursor.getColumnIndexOrThrow("place")); dueAmount = cursor.getString(cursor.getColumnIndexOrThrow("dueAmount")); dataModel.setShopId(shopId); dataModel.setShopName(shopName); dataModel.setTeluguName(teluguName); dataModel.setPlace(place); dataModel.setDueAmount(dueAmount); stringBuffer.append(dataModel); data.add(dataModel); } return data; } } 这个表我需要插入此JSON数据 APi的 - http://demo4896782.mockable.io/shops [ { "shopName": "Hello World.", "shopTeluguName": "శరవాన గుడ్డు పంపిణీదారులు", "shopAddress": "Bomanahalli", "previousDues": 0, "shopID": 1 }, { "shopName": "Hello World.", "shopTeluguName": "శరవాన గుడ్డు పంపిణీదారులు", "shopAddress": "Bomanahalli", "previousDues": 20, "shopID": 2 }, { "shopName": "Hello World.", "shopTeluguName": "శరవాన గుడ్డు పంపిణీదారులు", "shopAddress": "Bomanahalli", "previousDues": 400, "shopID": 3 } ] 预先感谢您。
...全文
相关推荐
JSONSchemaDatabase从JSON格式动态生成表并插入数据
创建数据库连接:根据你选择的数据库,配置连接参数,例如对于SQLite:```pythonfrom jsonschema2db import create_engineengine = create_engine
JSON_to_Database_Converter:Java项目的存储库,该项目将JSON文件的内容转换为SQLite数据库
JSON_to_Database_Converter是一个基于Java的项目,其主要功能是将JSON(JavaScript Object Notation)格式的数据转换并存储到SQLite数据库中。
Android参考源码-获取网络数据到本地并查看.zip
JSON解析:使用Gson将JSON字符串转换为Java对象。3. 数据存储:内部存储和SQLite数据库的使用,包括读写文件和执行SQL语句。4.
使用递归循环读取省市区json文件数据,并保存到数据库中
**数据库操作**: 数据库通常是关系型数据库,如MySQL、PostgreSQL或SQLite等。
省市县.db和区域编码
province_city.db"是一个SQLite数据库文件,这是Android系统广泛支持的一种轻量级数据库格式。


其他技术讨论专区
