From 0190125daca8a74bbdceadcbf58f45ee8b0c6173 Mon Sep 17 00:00:00 2001 From: 18516761980 <4761516tqsxp> Date: 星期二, 28 九月 2021 08:15:22 +0800 Subject: [PATCH] # --- src/main/java/com/zy/common/service/erp/ErpSqlServer.java | 81 +++++++++++++++++++++++++++++----------- 1 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/zy/common/service/erp/ErpSqlServer.java b/src/main/java/com/zy/common/service/erp/ErpSqlServer.java index 7f0610d..24a51e0 100644 --- a/src/main/java/com/zy/common/service/erp/ErpSqlServer.java +++ b/src/main/java/com/zy/common/service/erp/ErpSqlServer.java @@ -25,7 +25,7 @@ public class ErpSqlServer { // 鏁版嵁搴撹繛鎺� - private Connection conn; +// private Connection conn; // 鍒涘缓棰勭紪璇戣鍙ュ璞★紝涓�鑸兘鏄敤杩欎釜鑰屼笉鐢⊿tatement private PreparedStatement pstm = null; // 鍒涘缓涓�涓粨鏋滈泦瀵硅薄 @@ -69,8 +69,9 @@ private List<Map<String, Object>> executeQuery(String sql) { + Connection conn = null; try { - Connection conn = getConn(); + conn = getConn(); pstm = conn.prepareStatement(sql); rs = pstm.executeQuery(); // List<Map<String, Object>> maps = convertList(rs); @@ -80,13 +81,28 @@ return null; } finally { release(); + if (conn != null) { + try { + conn.close(); + conn = null; + } catch (SQLException e) { + e.printStackTrace(); + } + } } } private int executeUpdate(String sql) { + Connection conn = null; try { - Connection conn = getConn(); - pstm = conn.prepareStatement(sql); + conn = getConn(); + if(null != conn) + { + pstm = conn.prepareStatement(sql); + } else { + log.error("鏇存柊ERP涓棿琛ㄥけ璐�===>>鏁版嵁搴撹繛鎺onn涓虹┖"); + log.error("鏇存柊ERP涓棿琛ㄥけ璐�===>>" + sql); + } return pstm.executeUpdate(); } catch (Exception e) { e.printStackTrace(); @@ -95,6 +111,14 @@ return 0; } finally { release(); + if (conn != null) { + try { + conn.close(); + conn = null; + } catch (SQLException e) { + e.printStackTrace(); + } + } } } @@ -112,18 +136,29 @@ return list; } - public synchronized Connection getConn() throws SQLException { - if (null == this.conn || this.conn.isClosed()) { - try { - Class.forName(erpDbProperties.getDriver_class_name()).newInstance(); - this.conn = DriverManager.getConnection(erpDbProperties.getUr(), erpDbProperties.getUsername(), erpDbProperties.getPassword()); - } catch (Exception e) { - log.error("鑾峰彇ERP鏁版嵁搴撹繛鎺ュけ璐�"); - e.printStackTrace(); - throw new RuntimeException("鑾峰彇ERP鏁版嵁搴撹繛鎺ュけ璐�"); - } + //synchronized + public Connection getConn() throws SQLException { + Connection conn = null; + try { + Class.forName(erpDbProperties.getDriver_class_name()).newInstance(); + conn = DriverManager.getConnection(erpDbProperties.getUr(), erpDbProperties.getUsername(), erpDbProperties.getPassword()); + } catch (Exception e) { + log.error("鑾峰彇ERP鏁版嵁搴撹繛鎺ュけ璐�"); + e.printStackTrace(); + throw new RuntimeException("鑾峰彇ERP鏁版嵁搴撹繛鎺ュけ璐�"); } - return this.conn; + return conn; +// if (null == this.conn || this.conn.isClosed()) { +// try { +// Class.forName(erpDbProperties.getDriver_class_name()).newInstance(); +// this.conn = DriverManager.getConnection(erpDbProperties.getUr(), erpDbProperties.getUsername(), erpDbProperties.getPassword()); +// } catch (Exception e) { +// log.error("鑾峰彇ERP鏁版嵁搴撹繛鎺ュけ璐�"); +// e.printStackTrace(); +// throw new RuntimeException("鑾峰彇ERP鏁版嵁搴撹繛鎺ュけ璐�"); +// } +// } +// return this.conn; } private void release() { @@ -141,14 +176,14 @@ e.printStackTrace(); } } - if (conn != null) { - try { - conn.close(); - conn = null; - } catch (SQLException e) { - e.printStackTrace(); - } - } +// if (conn != null) { +// try { +// conn.close(); +// conn = null; +// } catch (SQLException e) { +// e.printStackTrace(); +// } +// } } /** -- Gitblit v1.9.1