Java自己动手写连接池一

时间:2021-11-02 00:44:05

自己动手写连接池,废话不多说,直接上代码,读取配置文件

package com.kama.cn;

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

public class ConfigurationManager {

private static final String CONFIG = "config.properties";

private static ConfigurationManager self = new ConfigurationManager();

private Properties props = new Properties();

private ConfigurationManager() {
InputStream in=null;
try
{
in = this.getClass().getClassLoader().getResourceAsStream(CONFIG);
props.load(in);
} catch (Exception e)
{
e.printStackTrace();

}finally
{
try
{
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

public String getValue(String key) {
return props.getProperty(key);
}

public static ConfigurationManager instance() {
return self;
}
}