1.新建一个configuer.properties文件,在src下新建包例如:com.db 然后把configure.properties文件放在该包中。
配置文件的内容如下
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/db
username=root
password=111111
他们都是key value对应的
2 在程序中读取文件信息
程序代码如下
配置文件的内容如下
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/db
username=root
password=111111
他们都是key value对应的
2 在程序中读取文件信息
程序代码如下
1.新建一个configure.properties文件,在src下新建包例如:com.db 然后把configure.properties文件放在该包中。
配置文件的内容如下
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/lwz
username=root
password=111111
他们都是key value对应的
2 在程序中读取文件信息
程序代码如下
public Connection getConnection() {
Properties properties = new Properties();
try {
properties.load(this.getClass().getResourceAsStream("com/db/configure.properties"));
String driver = properties.getProperty("driver");
String url = properties.getProperty("url");
String username = properties.getProperty("username");
String password = properties.getProperty("password");
try