public static String mysql_url;
public static String mysql_uname;
public static String mysql_passwd;
static{
Properties properties = new Properties();
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("/org/hzy/config/datasource.properties");
try {
properties.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
mysql_url=properties.getProperty("url");
mysql_uname=properties.getProperty("uname");
mysql_passwd=properties.getProperty("passworld");
System.out.print(properties.getProperty("initialContextfactory"));
System.out.print(properties.getProperty("providerURL"));
System.out.print(properties.getProperty("dataSource"));
}
getClass().getClassLoader().//默认的是src文件夹下
getClass()//表示当前包中的文件
转自:http://www.cnblogs.com/andysd/archive/2012/09/21/2697515.html
本文介绍了一个Java示例程序,该程序用于从配置文件中读取数据库连接信息,如URL、用户名和密码等,并展示了如何使用Properties类来加载这些属性。
155

被折叠的 条评论
为什么被折叠?



