在从json插入数据时,没有得到这样的表。首先,我具有存储注册详细信息,并且存储正确,但是不存储此数据。并且数据正确传递,但它没有显示此类表出口,我已对其进行了多次调试。这是我的Sqlite代码
public SQLiteDatabase myDatabase;
String TABLE_NAME = "customer";
public MobexInAppDb(Context context) {
super(context, "MyDb", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
String query;
//creating table
query = "CREATE TABLE " + TABLE_NAME + "(id integer primary key autoincrement," + "f_name text," + "l_name text," + "mobile text," + "email text," + "add1 text," + "add2 text," + "country text," + "state text," + "city text," + "zip text" + ")";
db.execSQL(query);
//db.execSQL("create table"+ TABLE_NAME + "( id integer primary key autoincrement," + "f_name text," + "l_name text," + "mobile text," + "email text," + "add1 text," + "add2 text," + "country text," + "state text," + "city text," + "zip text" + ");");
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
public void deleteButtonGroup(String tableName, String groupId, String sitecode) {
try {
myDatabase = this.getWritableDatabase();
String where = "sitecode + '" + sitecode + "' and groupId ='" + groupId + "'";
myDatabase.delete(tableName, where, null);
} catch (Exception e) {
e.printStackTrace();
}
}
public void insertButtonGroupData(String sitecode, String groupId, String groupName, String btnGrpStatus, String parentGroupId, String articleActive) {
try {
myDatabase = this.getWritableDatabase();
ContentValues dataToInsert = new ContentValues();
dataToInsert.put("sitecode", sitecode);
dataToInsert.put("groupId", groupId);
dataToInsert.put("groupName", groupName);
dataToInsert.put("btnGrpStatus", btnGrpStatus);
dataToInsert.put("parentGroupId", parentGroupId);
dataToInsert.put("articleActive", articleActive);
myDatabase.insertOrThrow("ButtonGroups", null, dataToInsert);
} catch (Exception e) {
e.printStackTrace();
}
}
这是我的方法,其中从json m将数据存储到sqlite
JSONArray buttnGroupDTOArray = response.getJSONArray("buttonGroupDTOArray");
for (int j = 0; j < buttnGroupDTOArray.length(); j++) {
JSONObject buttonGroupDTO = buttnGroupDTOArray.getJSONObject(j);
String groupID = buttonGroupDTO.getString("groupId");
String groupName = buttonGroupDTO.getString("groupName");
String btnGrpstatus = buttonGroupDTO.getString("status");
String parentGroupId = buttonGroupDTO.getString("parentGroupId");
String articleActive = buttonGroupDTO.getString("articleActive");
String siteCode = buttonGroupDTO.getString("sitecode");
mobexInAppDb.deleteButtonGroup("ButtonGroups", groupID, site);
mobexInAppDb.insertButtonGroupData(site,groupID,groupName,btnGrpstatus,parentGroupId,articleActive);
}
在MobexInAppDb类中,您已经创建了TABLE_NAME =“ customer”,但是在要插入表中的方法中,您正在插入的表“ ButtonGroups”尚未在所提供的代码中的任何地方创建。
您需要创建表“ ButtonGroups”才能插入json值。