- 数据库配置文件
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/seckill?characterEncoding=UTF-8
jdbc.user=root
jdbc.password=long
- 使用
private static Properties properties;
static{
properties=new Properties();
InputStream resourceAsStream = DBUtil.class.getClassLoader()
.getResourceAsStream("db.properties");
try {
properties.load(resourceAsStream);
} catch (IOException e) {
e.printStackTrace();
}
}
properties.getProperty("driver") //取值 括号中是属性名