• 数据库连接工厂


    package com.jikexueyuan.util;
    
    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.util.Properties;
    
    public class ConnectionFactory {
    	
    	private static String driver;
    	private static String dbrul;
    	private static String user;
    	private static String password;
    	private static final ConnectionFactory FACTORY = new ConnectionFactory();
    	private Connection conn;
    	
    	static{
    		Properties properties = new Properties();
    		try {
    			InputStream in = ConnectionFactory.class.getClassLoader().getResourceAsStream("dbconfig.properties");
    			properties.load(in);
    		} catch (Exception e) {
    			System.out.println("==========配置文件读取错误==========");
    		}
    		driver = properties.getProperty("driver");
    		dbrul = properties.getProperty("dburl");
    		user = properties.getProperty("user");
    		password = properties.getProperty("password");
    
    	}
    	
    	private ConnectionFactory(){
    		
    	}
    	
    	public static ConnectionFactory getInstance(){
    		return FACTORY;
    	}
    	
    	public Connection makeConnection(){
    		try {
    			Class.forName(driver);
    			conn = DriverManager.getConnection(dbrul, user, password);
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    		return conn;
    	}
    
    }
    

  • 相关阅读:
    数论
    2019牛客暑期多校训练营(第七场)
    C++大数模板
    网络流
    2019 Multi-University Training Contest 6
    无聊的数列
    Can you answer on these queries III
    Interval GCD
    2733:判断闰年-poj
    题目1083:特殊乘法-九度oj
  • 原文地址:https://www.cnblogs.com/mrbourne/p/9959454.html
Copyright © 2020-2023  润新知