package com.skic.util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

public class ConnectionFactory {
	private static String driverString;
	private static String dburlString;
	private static String userString;
	private static String pasString;
	private static final ConnectionFactory FACTORY = new ConnectionFactory();
	private Connection conn;
	static {
		Properties prop = new Properties();
		try {
			InputStream in = ConnectionFactory.class.getClassLoader().getResourceAsStream("dbconfig.properties");
			prop.load(in);
		} catch (IOException e1) {
			System.out.println("读取Properties文件出错");
			e1.printStackTrace();
		}
		driverString = prop.getProperty("driver");
		dburlString = prop.getProperty("db_url");
		userString = prop.getProperty("user");
		pasString = prop.getProperty("password");
	}

	private ConnectionFactory() {

	}

	public static ConnectionFactory getInstance() {
		return FACTORY;
	}

	public Connection makeConnection() {
		try {
			Class.forName(driverString);
			conn = DriverManager.getConnection(dburlString, userString, pasString);
		} catch (Exception e2) {
			System.out.println("数据库驱动加载失败");
			e2.printStackTrace();
		}
		return conn;
	}
}
