在我的 android 应用程序中,资产文件夹中有一个预定义的数据库。它有一个名为 WMExecutive Activity 的表。当用户输入数据并单击按钮时,我需要更新此表。这是我的活动。
case R.id.btnAdd:
if (description.getText().toString().trim().equals("")) {
Toast.makeText(getActivity(), "Description cannot be blank",
Toast.LENGTH_SHORT).show();
} else if (selectedComplain.equals("--Select--")) {
Toast.makeText(getActivity(), "Select a complain type to proceed",
Toast.LENGTH_SHORT).show();
} else {
SelectDBAdapter selectDBAdapter = SelectDBAdapter
.getDBAdapterInstance(mActivity);
try {
selectDBAdapter.openDataBase();
lstActivity = selectDBAdapter.getActivityDetails();
System.out.println("lstActivity.size >>>> "+lstActivity.size());
//Update WMExecutiveActivity table
//for(int i = 0; i < lstActivity.size(); i++){
nextActivityNo = lstActivity.get(0).getNextActivityNo();
complainActivityCatgry = lstActivity.get(0).getActivityCategory().toString();
//}
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//updatedOn = sdf.format(sys_date);
createdOn = sdf.format(sys_date);
String[] fieldLst = {"BusinessUnit", "ExecutiveCode", "ActivityNo", "ActivityCode", "ActivityType", "RetailerCode", "ProductCode", "ActivityDate", "FollowUpRequiredBefore",
"ActivityText", "VisitNumber", "VisitSequence","UpdatedBy", "CreatedOn", "CreatedBy", "UploadFlag", "Status", "ActivityStatus", "RecID"," ComplaintActivityCategory",
"ContactInfo", "TerritoryCode", "ComplaintDetail1"};
String[] valuesLst = {businessUnit, executiveCode, Integer.toString(nextActivityNo), activityCode, activityType, selectedRetCode, prodCode, strDate, date.getText().toString(),
selectedComplain, visitNo, visitSequence, executiveCode, createdOn, executiveCode, "1", "1", "0", "0", complainActivityCatgry,
contInfo.getText().toString(), territoryCode, description.getText().toString()};
DBAdapter dbAdapter = DBAdapter
.getDBAdapterInstance(mActivity);
dbAdapter.openDataBase();
boolean status = dbAdapter.updateExecActivity(fieldLst, valuesLst, "WMExecutiveActivity");
dbAdapter.close();
if (!status) {
Toast.makeText(getActivity(),
"Inserting data has been unsuccessfully!!! Try Later!!",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getActivity(),
"Inserting data has been successfully!!!",
Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
selectDBAdapter.close();
e.printStackTrace();
} finally {
selectDBAdapter.close();
}
这是我的 DBAdapter 类段。
public boolean updateExecActivity(String[] fieldLst, String[] valuesLst, String tblname) {
boolean status = true;
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date();
String updatedOn = sdf.format(date);
try {
myDataBase.beginTransaction();
ContentValues values = new ContentValues();
for (int i = 0; i < fieldLst.length; i ++){
values.put(fieldLst[i], valuesLst[i]);
}
values.put("UpdatedOn", updatedOn);
System.out.println("values>>>>"+values.size());
long exeActivity = myDataBase.update(tblname, values, null, null);
System.out.println("exeActivity>>>"+exeActivity);
if(exeActivity == -1){
System.out.println("status>>>"+status);
status = false;
throw new Exception(
"There are some error in inserting data to WMExecutiveActivity");
}
myDataBase.setTransactionSuccessful();
} catch (Exception e) {
status = false;
e.printStackTrace();
Log.i("==DBAdapter==updateExecActivity>>>>"
+ DBAdapter.class.toString(), e.getMessage());
} finally {
myDataBase.endTransaction();
}
return status;
}
但问题是它没有更新表格。更新方法返回零。它显示了一个 toast插入数据已经成功!!!.
谁能解释一下这有什么问题。
提前致谢