上面的代码在Mysql表中插入多行。我想让它失败证明,即如果连接在插入之间插入,如何回滚所有内容?
for (int i = 0; i < items.size(); i += 4) {
ArrayList listItems = new ArrayList();
item_id = Integer.parseInt(items.get(i));
quantity = Integer.parseInt(items.get(i + 3));
itemTotPrice = (BigDecimal.valueOf(Double.parseDouble(items
.get(i + 2)))).multiply(BigDecimal.valueOf(quantity));
nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("order_id", String
.valueOf(order_id)));
nameValuePairs.add(new BasicNameValuePair("item_id", String
.valueOf(item_id)));
nameValuePairs.add(new BasicNameValuePair("quantity", String
.valueOf(quantity)));
nameValuePairs.add(new BasicNameValuePair("totalAmount", String
.valueOf(itemTotPrice)));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
try {
if (isNetworkAvailable()) {
response = httpclient.execute(httppost);
runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
Toast.makeText(
BillSummary.this,
"Your order is placed. We will call you soon for confirmation!",
Toast.LENGTH_SHORT).show();
Intent i = new Intent(BillSummary.this,
OrderSummary.class);
i.putExtra("address1", address1);
i.putExtra("address2", address2);
i.putExtra("amount", tvTotalBill.getText()
.toString());
startActivity(i);
finish();
}
});
} else {
runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
Toast.makeText(BillSummary.this,
"No Internet Connection!",
Toast.LENGTH_SHORT).show();
}
});
}
} catch (Exception e) {
runOnUiThread(new Runnable() {
public void run() {
dialog.dismiss();
Toast.makeText(
BillSummary.this,
"Connection Timed Out.Problem with the network!",
Toast.LENGTH_SHORT).show();
}
});
}
}
上面的代码在Mysql表中插入多行。我想让它失败证明,即如果连接在插入之间插入,如何回滚所有内容?