properties 配置文件

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();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值