一个简单的jdbc
来源:互联网 发布:vb.net excel 数据库 编辑:程序博客网 时间:2024/06/06 03:58
************************************************************************************************************
public class JdbcUtil {
//第一种方法: private String url = "jdbc:mysql://localhost:3306/day17";
private static String url = "jdbc:mysql:///day17";//第二种方法
private static String user = "root";
private static String password = "root";
//写成静态方法,用类名.getConnection()获取该连接对象
public static Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection(url, user, password);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 关闭
* 关闭原则:后开先关
*/
public static void closeAll(Connection con, Statement stmt, ResultSet rs) {
try {
if (rs != null) {
rs.close();
rs = null; // 建议释放资源
}
if (stmt != null) {
stmt.close();
stmt = null;
}
if (con != null && !con.isClosed()) {
con.close();
con = null;
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
* 关闭
* 关闭原则:后开先关
*/
public static void closeAll(Connection con, Statement stmt, ResultSet rs) {
try {
if (rs != null) {
rs.close();
rs = null; // 建议释放资源
}
if (stmt != null) {
stmt.close();
stmt = null;
}
if (con != null && !con.isClosed()) {
con.close();
con = null;
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
阅读全文
0 0
- 一个简单的jdbc
- 一个简单的JDBC 例子
- 一个简单的JDBC程序
- 一个简单的JDBC的实现
- 一个简单的 JDBC 包装器
- 一个简单的 JDBC 包装器
- 一个简单的 JDBC 包装器
- 一个简单的 JDBC 包装器
- JDBC的一个简单封装类DBUtil
- 一个JDBC事务处理的简单例子
- 一个简单封装的jdbc工具类
- 一个简单的JDBC优化实例
- 一个简单的jdbc连接封装
- 一个JDBC简单的查询步骤
- 一个简单的JDBC操作对象的封装
- 用JDBC实现简单的数据库查询的一个例子
- 无聊编写的一个简单的JDBC封装类
- 一个简单的基于spring jdbc的扩展
- Linux单元小结(2)
- 算法题练习系列之(三十六): 养兔子
- Hashtable
- 【Linux】Vim修改tab为4个空格
- POJ1577 二叉排序树
- 一个简单的jdbc
- 第一篇博客--男人与男孩的区别
- THINKPHP5.0 在Liunx中配置伪静态 (URL重写)规则(解决万网虚拟空间linux系统下报错)
- 贪心算法总结
- C++一本通题库1019
- 声明
- Lucene入门教程
- JDBC(一)
- 后缀表达式求值