public class DBUtil {
public static Connection getConn() {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bbs", "root", "root");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}

public static PreparedStatement prepareStmt(Connection conn, String sql) {
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return pstmt;
}

public static ResultSet executeQuery(Statement stmt, String sql) {
ResultSet rs = null;
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}

public static void close(Connection conn, Statement stmt,
PreparedStatement preStatement, ResultSet rs) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
conn = null;
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
stmt = null;
}
if (preStatement != null) {
try {
preStatement.close();
} catch (SQLException e) {
e.printStackTrace();
}
preStatement = null;
}

if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
rs = null;
}
}
}

最新文章

  1. [LeetCode] Combination Sum IV 组合之和之四
  2. 《Learning Highcharts》中文翻译
  3. .NET Core全新路线图(译)
  4. Java系列:JVM指令详解(下)(zz)
  5. ionic2 页面加载时图片添加的问题
  6. Beaglebone Back学习七(URAT串口测试)
  7. 转:尝试用Gearman实现分布式处理(PHP)
  8. Css的三大机制(特性):特殊性、继承、层叠详解
  9. CentOS用gparted实现无损调整磁盘分区大小
  10. 程序员眼中的UML
  11. ArcGIS网络分析之Silverlight客户端最近设施点分析(四)
  12. HDU-1495 非常可乐 (嵌套结构体-广搜 对比 一般广搜)
  13. c#中数组的总结
  14. C++与C的区别
  15. paymob QB冲值接口
  16. HANA 与 Oracle 12c哪一个更快
  17. InnoDB表空间、段、区
  18. Strandbeest mechanism and Leg mechanism
  19. ABP 邮箱设置
  20. JsonCpp使用方法详解

热门文章

  1. 页面js框架
  2. R中的基本函数运算
  3. java:OutputStream和InputStream 输出输入流,FileOutputStream,FileInputStream写入读取流
  4. 利用CocoaLumberjack框架+XcodeColors插件,调试输出有彩色的信息
  5. python里混淆矩阵 左下角为漏报,右上角为误报
  6. 打印a*a的乘法表
  7. C++继承细节 -1
  8. pdp 的连接方法
  9. Spring框架环境搭建
  10. grep---Linux下文本处理五大神器之五