“DbUtils类关闭资源的操作”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) (建立内容为“https://www.bilibili.com/video/BV1eJ411c7rf/?p=55”的新页面) |
Jihongchang(讨论 | 贡献) |
||
第1行: | 第1行: | ||
https://www.bilibili.com/video/BV1eJ411c7rf/?p=55 | https://www.bilibili.com/video/BV1eJ411c7rf/?p=55 | ||
+ | |||
+ | DbUtils 是 commons-dbutils-1.3.jar 中提供的工具类<syntaxhighlight lang="java"> | ||
+ | /** | ||
+ | * 使用 dbutils.jar 中提供的 DbUtils 工具类实现资源的关闭 | ||
+ | * 关闭连接和 Statement 的操作 | ||
+ | * @param conn | ||
+ | * @param ps | ||
+ | */ | ||
+ | public static void closeResource1(Connection conn, Statement ps, ResultSet rs){ | ||
+ | // try { | ||
+ | // DbUtils.close(rs); | ||
+ | // } catch (SQLException e) { | ||
+ | // e.printStackTrace(); | ||
+ | // } | ||
+ | // | ||
+ | // try { | ||
+ | // DbUtils.close(ps); | ||
+ | // } catch (SQLException e) { | ||
+ | // e.printStackTrace(); | ||
+ | // } | ||
+ | // | ||
+ | // try { | ||
+ | // DbUtils.close(conn); | ||
+ | // } catch (SQLException e) { | ||
+ | // e.printStackTrace(); | ||
+ | // } | ||
+ | |||
+ | // DbUtils.closeQuietly(rs); | ||
+ | // DbUtils.closeQuietly(ps); | ||
+ | // DbUtils.closeQuietly(conn); | ||
+ | |||
+ | DbUtils.closeQuietly(conn, ps, rs); | ||
+ | |||
+ | } | ||
+ | </syntaxhighlight>https://github.com/jihch/jdbc_2/blob/main/src/main/java/io/github/jihch/util/JDBCUtils.java |
2023年1月14日 (六) 07:32的最新版本
https://www.bilibili.com/video/BV1eJ411c7rf/?p=55
DbUtils 是 commons-dbutils-1.3.jar 中提供的工具类
/**
* 使用 dbutils.jar 中提供的 DbUtils 工具类实现资源的关闭
* 关闭连接和 Statement 的操作
* @param conn
* @param ps
*/
public static void closeResource1(Connection conn, Statement ps, ResultSet rs){
// try {
// DbUtils.close(rs);
// } catch (SQLException e) {
// e.printStackTrace();
// }
//
// try {
// DbUtils.close(ps);
// } catch (SQLException e) {
// e.printStackTrace();
// }
//
// try {
// DbUtils.close(conn);
// } catch (SQLException e) {
// e.printStackTrace();
// }
// DbUtils.closeQuietly(rs);
// DbUtils.closeQuietly(ps);
// DbUtils.closeQuietly(conn);
DbUtils.closeQuietly(conn, ps, rs);
}
https://github.com/jihch/jdbc_2/blob/main/src/main/java/io/github/jihch/util/JDBCUtils.java