首页>代码>jsp+servlet+easyUI+jquery+echarts开发高速公路事故后台信息管理系统>/OneProject/src/com/wu/action/AccidentImpl.java
package com.wu.action; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import com.wu.Service.AccidentI; import com.wu.bean.Accident; import com.wu.util.DbUtil; import com.wu.util.jsonUtil; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class AccidentImpl implements AccidentI { @Override public boolean AddCar(Accident car) { boolean flag=false; Connection conn = null; PreparedStatement pst = null; int result = 0; String sql1="insert into accident_info" + " values(?,?,?,?,?)"; String sql2="insert into accident" + " values(?,?,?,?,?)"; try { conn=DbUtil.getConnection(); pst = conn.prepareStatement(sql2); pst.setInt(1, car.getAcc_ID()); pst.setString(2, car.getAcc_Time()); pst.setString(3, car.getAcc_Address()); pst.setString(4, car.getAcc_police()); pst.setString(5, car.getAcc_des()); result = pst.executeUpdate(); conn.setAutoCommit(true); DbUtil.closeAll(); if(result!=0){ flag =true; } if(flag){ conn=DbUtil.getConnection(); pst = conn.prepareStatement(sql1); pst.setInt(1, car.getAcc_ID()); pst.setString(2, car.getAcc_Type()); pst.setString(3, car.getAcc_Picture()); pst.setInt(4, car.getAcc_Number()); pst.setDouble(5, car.getAcc_Money()); result = pst.executeUpdate(); conn.setAutoCommit(true); DbUtil.closeAll(); if(result!=0){ return true; } } } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } return false; } /** * 查询全部 */ @Override public JSONArray selAll() { JSONArray jsonArray = null; String sql="select * from accident_info"; Connection conn = null; PreparedStatement pst = null; ResultSet rs = null; try { conn=DbUtil.getConnection(); pst = conn.prepareStatement(sql); rs = pst.executeQuery(); jsonArray = jsonUtil.formatRsToJsonArray(rs); DbUtil.closeAll(); } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } return jsonArray; } @Override public JSONArray search(int acc_id) { JSONArray jsonArray = null; String sql="select * from accident_info where acc_Id=?"; Connection conn = null; PreparedStatement pst = null; ResultSet rs = null; try { conn=DbUtil.getConnection(); pst = conn.prepareStatement(sql); pst.setInt(1, acc_id); //pst.setString(1, name); rs = pst.executeQuery(); jsonArray = jsonUtil.formatRsToJsonArray(rs); DbUtil.closeAll(); } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } return jsonArray; } @Override public boolean Update(Accident car) { boolean flag=false; Connection conn = null; PreparedStatement pst = null; int result = 0; String sql1="update accident set acc_des=? " + "where acc_ID=?"; String sql2="update accident_info set acc_Type=? , acc_Picture=?, acc_Number=?,acc_Money=? " + "where acc_Id=?"; try { conn=DbUtil.getConnection(); pst = conn.prepareStatement(sql1); pst.setString(1, car.getAcc_des()); pst.setInt(2, car.getAcc_ID()); result = pst.executeUpdate(); conn.setAutoCommit(true); DbUtil.closeAll(); if(result!=0){ flag=true; } if(flag){ conn=DbUtil.getConnection(); pst = conn.prepareStatement(sql2); pst.setString(1, car.getAcc_Type()); pst.setString(2, car.getAcc_Picture()); pst.setInt(3, car.getAcc_Number()); pst.setDouble(4, car.getAcc_Money()); pst.setInt(5, car.getAcc_ID()); result = pst.executeUpdate(); conn.setAutoCommit(true); DbUtil.closeAll(); if(result!=0){ return true; } } } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } return false; } @Override public boolean delete(Accident car) { boolean flag=false; Connection conn = null; PreparedStatement pst = null; int result = 0; String sql1="delete from accident where acc_ID=?"; String sql2="delete from accident_info where acc_Id=?"; try { conn=DbUtil.getConnection(); pst = conn.prepareStatement(sql2); pst.setInt(1, car.getAcc_ID()); result = pst.executeUpdate(); conn.setAutoCommit(true); DbUtil.closeAll(); if(result!=0){ flag=true; } if(flag){ conn=DbUtil.getConnection(); pst = conn.prepareStatement(sql1); pst.setInt(1, car.getAcc_ID()); result = pst.executeUpdate(); conn.setAutoCommit(true); DbUtil.closeAll(); if(result!=0){ return true; } } } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } return false; } @Override public JSONArray show() { JSONArray jsonArray = null; String sql="select * from accident"; Connection conn = null; PreparedStatement pst = null; ResultSet rs = null; try { conn=DbUtil.getConnection(); pst = conn.prepareStatement(sql); rs = pst.executeQuery(); jsonArray=changeJasson(rs); DbUtil.closeAll(); } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } return jsonArray; } public JSONArray changeJasson(ResultSet rs) throws SQLException{ JSONArray jsonArray = null; int a=0,b=0,c=0; while(rs.next()){ String time=rs.getString("2"); time=jsonUtil.TimeForm(time); if(time.equals("2017")){ a++; } if(time.equals("2018")){ b++; } if(time.equals("2019")){ c++; } } JSONObject one=new JSONObject(); JSONObject two=new JSONObject(); JSONObject three=new JSONObject(); one.put("2017", a); two.put("2018",b); three.put("2019", c); jsonArray.add(one); jsonArray.add(two); jsonArray.add(three); return jsonArray; } }

171337601 LV9
2022年4月18日
nitama LV19
2021年5月16日
ericxu1116 LV24
2021年4月26日
rebecca0214 LV2
2021年4月14日
ly_fxm LV4
2021年1月31日
naixia LV9
2020年7月8日
芳华林 LV11
2020年6月18日
骄傲的时刻 LV2
2020年5月16日
KING QIN LV5
2020年5月12日
TerryGaoBo LV9
2020年4月28日