1. 创建一个source folder 起名config
2. 创建一个jdbc.properties文件
3. 写jdbc配置
driverName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/database_name
username=root
password=123456
- 读取配置文件jdbc.properties
Properties prop = new Properties();
//加载配置文件:类加载器相对于类加载路径src 源码文件夹source folder:config
InputStream is = JdbcUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
prop.load(is);
driverName = prop.getProperty("driverName");
url=prop.getProperty("url);
username=prop.getProperty("username");
password=prop.getProperty("password");