jdbc —>java database connection java 数据库 连接
- 01properties文件与properties类
properties文件是一种java能够配置文件
用于储存配置文件
格式为文本文件,其中用键值对 形式储存配置信息
可用”#” 来做注释 - 02 Properties类,主要用于读取Java配置文件.
Properties类表示一组持久的属性.
properties属性可以保存到流中或从流中加载.
properties属性列表中的每个键及其对应的值都是一个字符串.
properties属性列表可以包含另一个属性列表作为其”默认值”
如果在原始属性列表中
db.properties文件
driverName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/car?useUnicod=true&
characterEncoding=utf-8
userName=root
passWord=123456
properties类
Properties pr=new Properties();
try { pr.load(DBUtil.class.getClassLoader().getResourceAsStream(“db.properties”));?????
driverName=pr.getProperty(“driverName”);
url=pr.getProperty(“url”);
userName=pr.getProperty(“userName”);
passWord=pr.getProperty(“passWord”);
Class.forName(driverName);
}catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}