DBManager.java
上传用户:liangcc
上传日期:2019-05-24
资源大小:4412k
文件大小:1k
- package com.softeem.webmail.dao;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class DBManager {
- public final static String url = "jdbc:mysql://localhost:3306/mail";
- public final static String name = "root";
- public final static String password = "root";
- private static Connection conn = null;
- static {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- public static Connection getConnection() {
- try {
- conn = DriverManager.getConnection(url, name, password);
- } catch (SQLException e) {
- System.out.println("连接失败..." + e);
- conn = null;
- }
- return conn;
- }
- public static void closeConnection(ResultSet rs, Statement st,
- Connection con) {
- try {
- if (rs != null) {
- rs.close();
- rs = null;
- }
- if (st != null) {
- st.close();
- st = null;
- }
- if (con != null) {
- con.close();
- con = null;
- }
- } catch (SQLException e) {
- System.out.println("关闭连接失败..." + e);
- }
- }
- }