package com.point.strategy.oaDocking.service; import com.point.strategy.common.SystemProperty; import java.sql.*; import java.util.logging.Level; import java.util.logging.Logger; public class CityBusinessSystemIntegration { private static final Logger LOGGER = Logger.getLogger(CityBusinessSystemIntegration.class.getName()); private static final String driver = SystemProperty.getKeyValue("cityBusiness.driverClassName", "application.properties"); private static final String url = SystemProperty.getKeyValue("cityBusiness.url", "application.properties"); private static final String user = SystemProperty.getKeyValue("cityBusiness.username", "application.properties"); private static final String password = SystemProperty.getKeyValue("cityBusiness.password", "application.properties"); // 获取数据库连接 private static Connection getConnection() throws Exception { Class.forName(driver); return DriverManager.getConnection(url, user, password); } // 查询 public static ResultSet executeQuery(String sql) throws Exception { Connection conn = null; Statement st = null; try { conn = getConnection(); st = conn.createStatement(); return st.executeQuery(sql); } catch (Exception e) { LOGGER.log(Level.SEVERE, "执行查询时出错: " + sql, e); closeResources(conn, st, null); throw e; } } // 修改 public static int executeUpdate(String sql) throws Exception { Connection conn = null; Statement st = null; try { conn = getConnection(); st = conn.createStatement(); return st.executeUpdate(sql); } catch (Exception e) { LOGGER.log(Level.SEVERE, "执行更新时出错: " + sql, e); throw e; } finally { closeResources(conn, st, null); } } // 关闭资源 public static void closeResources(Connection conn, Statement st, ResultSet rs) { try { if (rs != null) rs.close(); if (st != null) st.close(); if (conn != null) conn.close(); } catch (Exception e) { LOGGER.log(Level.WARNING, "关闭资源时出错", e); } } }