jdbc抽取到工具类中:
public class CopyUtils {
private Properties properties;
private static CopyUtils copyUtils;
private CopyUtils(){
//通过构造方法来执行加载properites文件
try {
FileInputStream fis = new FileInputStream("database.properties" );
properties =new Properties();
properties.load(fis);
} catch (IOException e) {
e.printStackTrace();
}
}
public static synchronized CopyUtils getCopyUtils(){
if(copyUtils==null){
synchronized (CopyUtils.class){
copyUtils =new CopyUtils();
}
}
return copyUtils;
}
public String getValue(String key){
return properties.getProperty(key);
}
}