关闭数据库连接的代码块
代码块语法遵循标准markdown代码,例如:
public static void closePreConn(ResultSet rs, PreparedStatement pstmt, Connection conn) {
DBConfig dbConfig = DBConfig.loadDBConfig();
try {
if (rs != null) {//如果返回的结果集对象不能为空,就关闭连接
rs.close();
}
} catch (Exception e) {
e.printStackTrace();
}
try {
if (pstmt != null) {
pstmt.close();//关闭预编译对象
}
} catch (Exception e) {
e.printStackTrace();
}
try {
if (conn != null) {
if(Common.CONFIG_MONITOR_TYPE_DATABASE.equals(dbConfig.getMonitorType())){
conn.close();//关闭连接对象
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
//获取数据库信息的方法
public static DBConfig loadDBConfig(){
if(Util.isNull(DBConfig.dbConfig)){
String rootPath = Util.getRootPath();
File configPathFile = new File(rootPath + "\\configFilePath\\dbConfig.js");
String json = JSON.getStringFromFile(configPathFile);
DBConfig.dbConfig = JSON.fromJson(json, DBConfig.class);
}
return DBConfig.dbConfig;
}