/**
* 批量插入数据
*
* @param json
* @param payment
* @param orderId
*/
private int[] batchOperate(JSONArray json, String payment, String orderId, Long userId, String cartId) {
PreparedStatement pstmt = null;
Connection conn = null;
// Savepoint sp = null;
try {
StringBuilder sql = new StringBuilder();
sql.append("insert into tb_order(userid, itemid, amount, payment, orderid, createdate, updatedate, isdeleted)");
sql.append(" values(?, ?, ?, ?, ?, sysdate, sysdate, 0)");
conn = OracleDb.getConnection(DbConstant.DBNAME);
// sp = conn.setSavepoint();
pstmt = conn.prepareStatement(sql.toString());
for (Object obj : json) {
JSONObject jsonObject = JSONObject.fromObject(obj);
pstmt.setObject(1, userId);
pstmt.setObject(2, jsonObject.get("id"));
pstmt.setObject(3, jsonObject.get("amount"));
pstmt.setObject(4, payment);
pstmt.setObject(5, orderId);
pstmt.addBatch();
}
int[] result = pstmt.executeBatch();
conn.commit();
//删除购物车
mongoSupermarketService.deleteCart(cartId);
//启动发送消息的线程
return result;
} catch (Exception e) {
e.printStackTrace();
try {
conn.rollback();
} catch (Exception ex) {
Logger.getLogger(SupermarketService.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
* 批量插入数据
*
* @param json
* @param payment
* @param orderId
*/
private int[] batchOperate(JSONArray json, String payment, String orderId, Long userId, String cartId) {
PreparedStatement pstmt = null;
Connection conn = null;
// Savepoint sp = null;
try {
StringBuilder sql = new StringBuilder();
sql.append("insert into tb_order(userid, itemid, amount, payment, orderid, createdate, updatedate, isdeleted)");
sql.append(" values(?, ?, ?, ?, ?, sysdate, sysdate, 0)");
conn = OracleDb.getConnection(DbConstant.DBNAME);
// sp = conn.setSavepoint();
pstmt = conn.prepareStatement(sql.toString());
for (Object obj : json) {
JSONObject jsonObject = JSONObject.fromObject(obj);
pstmt.setObject(1, userId);
pstmt.setObject(2, jsonObject.get("id"));
pstmt.setObject(3, jsonObject.get("amount"));
pstmt.setObject(4, payment);
pstmt.setObject(5, orderId);
pstmt.addBatch();
}
int[] result = pstmt.executeBatch();
conn.commit();
//删除购物车
mongoSupermarketService.deleteCart(cartId);
//启动发送消息的线程
return result;
} catch (Exception e) {
e.printStackTrace();
try {
conn.rollback();
} catch (Exception ex) {
Logger.getLogger(SupermarketService.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}