fb8bae3a7d69373b8278e86b1e3592d8319a28b9.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package com.cockpit.dao;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.Date;
  7. import java.util.List;
  8. import com.cockpit.vo.LineTripOut;
  9. import com.persistence.DBdll.SysOperator;
  10. import com.sinosoft.cm.DBUtils;
  11. import com.sinosoft.cm.common.ArrayList;
  12. public class UtilDao {
  13. public List<LineTripOut> getLineTripList(){
  14. Connection conns = DBUtils.getConnection();
  15. PreparedStatement pss=null;
  16. ResultSet rs=null;
  17. List<LineTripOut> lineTripList = new ArrayList<LineTripOut>();
  18. String sql = "SELECT * FROM NWYJ.ECM_OMS_LINE_TRIP_OUT";
  19. try{
  20. pss = conns.prepareStatement(sql);
  21. rs = pss.executeQuery();
  22. while(rs.next()){
  23. LineTripOut lto = new LineTripOut(
  24. rs.getString("FD_OBJECTID"),
  25. rs.getString("VIPCONSUMER"),
  26. rs.getString("EQUIPMENTID"),
  27. rs.getString("EQUIPMENTNAME"),
  28. rs.getString("RECLOSE"),
  29. rs.getString("STATIONNAME"),
  30. rs.getString("VOLLEVEL"),
  31. rs.getString("INSTITUTIONS"),
  32. rs.getString("SUBSTATION"),
  33. rs.getString("ONTIME"),
  34. rs.getString("MAINTENANCEDEPARTMENT"),
  35. rs.getString("PHASE"),
  36. rs.getString("RECORD"),
  37. rs.getString("LOSTLOAD"),
  38. rs.getString("AREA"),
  39. rs.getString("INAREAID"),
  40. rs.getDate("TRIPTIME"),
  41. rs.getString("CONSUMER"),
  42. rs.getString("IS_DEL"),
  43. rs.getDate("UPDATEDATE"));
  44. lineTripList.add(lto);
  45. }
  46. return lineTripList;
  47. }catch(SQLException e){ e.printStackTrace(); }
  48. finally{
  49. try {
  50. if(rs != null)
  51. rs.close();
  52. if(pss != null)
  53. pss.close();
  54. if(conns != null)
  55. conns.close();
  56. } catch (SQLException e) { e.printStackTrace(); }
  57. }
  58. return null;
  59. }
  60. public void addLineTripBatch(List<LineTripOut> ltList){
  61. Connection conn = DBUtils.getConnection();
  62. PreparedStatement ps=null;
  63. String addSql = "insert into NWYJ_SERVICE.OSM_OUTAGETRIP(\"OBJ_ID\", \"VIPCONSUMER\", " +
  64. "\"EQUIPMENTNAME\", \"RECLOSE\", \"STATIONNAME\", \"VOLLEVEL\", \"AREA\", " +
  65. "\"SUBSTATION\", \"ONTIME\", \"MAINTENANCEDEPARTMENT\", \"PHASE\", " +
  66. "\"RECODE\", \"LOSTLOAD\", \"TRIPTIME\", \"CONSUMER\", " +
  67. "\"UP_DATE\") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ";
  68. try{
  69. //事务提交方式为非自动
  70. conn.setAutoCommit(false) ;
  71. ps = conn.prepareStatement(addSql) ;
  72. for (LineTripOut entity : ltList){
  73. ps.setObject(1, entity.getFD_OBJECTID());
  74. ps.setObject(2, entity.getVIPCONSUMER());
  75. ps.setObject(3, entity.getEQUIPMENTNAME());
  76. ps.setObject(4, entity.getRECLOSE());
  77. ps.setObject(5, entity.getSTATIONNAME());
  78. ps.setObject(6, entity.getVOLLEVEL());
  79. ps.setObject(7, entity.getAREA());
  80. ps.setObject(8, entity.getSUBSTATION());
  81. ps.setObject(9, entity.getONTIME());
  82. ps.setObject(10, entity.getMAINTENANCEDEPARTMENT());
  83. ps.setObject(11, entity.getPHASE());
  84. ps.setObject(12, entity.getRECORD());
  85. ps.setObject(13, entity.getLOSTLOAD());
  86. ps.setObject(14, entity.getTRIPTIME());
  87. ps.setObject(15, entity.getCONSUMER());
  88. System.out.println(entity.getUPDATEDATE());
  89. ps.setObject(16, entity.getUPDATEDATE());
  90. ps.addBatch();
  91. }
  92. ps.executeBatch();
  93. conn.commit();
  94. System.out.println("ok!!!");
  95. } catch (SQLException e){
  96. try{ conn.rollback(); }
  97. catch (SQLException e1){ e1.printStackTrace(); }
  98. e.printStackTrace();
  99. } finally {
  100. try{ conn.setAutoCommit(true); }
  101. catch(SQLException e){ e.printStackTrace(); }
  102. finally{
  103. try {
  104. if(ps != null)
  105. ps.close();
  106. if(conn != null)
  107. conn.close();
  108. } catch (SQLException e) { e.printStackTrace(); }
  109. }
  110. }
  111. }
  112. public static void main(String arrgs[]){
  113. UtilDao udao = new UtilDao();
  114. // new UtilDao().addLineTripBatch(new UtilDao().getLineTripList());
  115. udao.addLineTripBatch(udao.getLineTripList());
  116. }
  117. }