package com.sino.publicclass.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtils {
	private static String url = "jdbc:mysql://www.sino-assist.com:3306/weixin";
	private static String user = "root";
	private static String password = "123456";
	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	private DBUtils() {
	}

	/**
	 * 提供数据库连接对象
	 * 
	 * @return
	 */
	public static Connection getConnection() {
		Connection conn = null;
		try {
			conn = DriverManager.getConnection(url, user, password);
		} catch (SQLException e) {
			e.printStackTrace();
			System.out.println("数据库连接对象创建失败");
		}
		return conn;
	}
	/**
	 * 关闭连接对象
	 * @param conn
	 */
	public static void close(Connection conn){
		try {
			if(conn!=null&&!conn.isClosed()){
				conn.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		 System.out.println(getConnection());
	}

}
