在com.app.resource下有db.properties
读取
connection.driver=com.mysql.jdbc.Driver
connection.url=jdbc:mysql://localhost:3306/database
connection.username=root
connection.password=root
读取
try {
ResourceBundle bundle = ResourceBundle.getBundle("com/app/resource/db");
driver = bundle.getString("connection.driver");
url = bundle.getString("connection.url");
user = bundle.getString("connection.username");
pwd = bundle.getString("connection.password");
} catch (Exception ex) {
ex.printStackTrace();
}
本文介绍了一种在Java应用程序中加载数据库连接配置的方法。通过使用ResourceBundle来获取位于com.app.resource下的db.properties文件中的配置信息,包括数据库驱动、URL、用户名及密码。

被折叠的 条评论
为什么被折叠?



