| | |
| | | |
| | | private List<Map<String, Object>> executeQuery(String sql) { |
| | | Connection conn = null; |
| | | PreparedStatement pstm = null; |
| | | ResultSet rs = null; |
| | | try { |
| | | conn = getConn(); |
| | | pstm = conn.prepareStatement(sql); |
| | | |
| | | pstm.setQueryTimeout(QUERY_TIMEOUT_SECONDS); |
| | | |
| | | rs = pstm.executeQuery(); |
| | | // List<Map<String, Object>> maps = convertList(rs); |
| | | |
| | | // ✅ 先把 rs 转换完再关闭连接 |
| | | return convertList(rs); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } finally { |
| | | release(); |
| | | if (conn != null) { |
| | | try { |
| | | // ❗不能提前调用 release(),改为手动释放各对象 |
| | | try { |
| | | if (rs != null) { |
| | | rs.close(); |
| | | rs = null; |
| | | } |
| | | if (pstm != null) { |
| | | pstm.close(); |
| | | pstm = null; |
| | | } |
| | | if (conn != null) { |
| | | conn.close(); |
| | | conn = null; |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | public Number executeQueryCount(String sql, String column) { |
| | | Number value = 0; |
| | | Connection conn = null; |