Connection conn = null; try { conn = DbKit.getConfig().getConnection();//获取连接 DbKit.getConfig().setThreadLocalConnection(conn); conn.setAutoCommit(false);//自动提交变成false //存储操作 conn.commit();//提交保存,确定存入 Map map=new HashMap(); map.put("code",0); map.put("msg",Consts.SAVE_SUCCESS); renderJson(map); } catch (Exception e) { try { if (null != conn) conn.rollback();//回滚 } catch (Exception e1) { e1.printStackTrace(); } Map map=new HashMap(); map.put("code",1); map.put("msg",Consts.SAVE_FAILED); renderJson(map); } finally { try { if (null != conn) {conn.close();} } catch (Exception e2) { e2.printStackTrace(); } finally { DbKit.getConfig().removeThreadLocalConnection(); } }