DBManager.java
上传用户:liangcc
上传日期:2019-05-24
资源大小:4412k
文件大小:1k
源码类别:

WEB邮件程序

开发平台:

Java

  1. package com.softeem.webmail.dao;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. public class DBManager {
  8. public final static String url = "jdbc:mysql://localhost:3306/mail";
  9. public final static String name = "root";
  10. public final static String password = "root";
  11. private static Connection conn = null;
  12. static {
  13. try {
  14. Class.forName("com.mysql.jdbc.Driver");
  15. } catch (ClassNotFoundException e) {
  16. e.printStackTrace();
  17. }
  18. }
  19. public static Connection getConnection() {
  20. try {
  21. conn = DriverManager.getConnection(url, name, password);
  22. } catch (SQLException e) {
  23. System.out.println("连接失败..." + e);
  24. conn = null;
  25. }
  26. return conn;
  27. }
  28. public static void closeConnection(ResultSet rs, Statement st,
  29. Connection con) {
  30. try {
  31. if (rs != null) {
  32. rs.close();
  33. rs = null;
  34. }
  35. if (st != null) {
  36. st.close();
  37. st = null;
  38. }
  39. if (con != null) {
  40. con.close();
  41. con = null;
  42. }
  43. } catch (SQLException e) {
  44. System.out.println("关闭连接失败..." + e);
  45. }
  46. }
  47. }