Java数据库连接配置文件读取不到,文件是在SRC目录下的
publicstaticConnectiongetConnection(){Propertiespro=newProperties();Connectionconnect...
public static Connection getConnection(){
Properties pro = new Properties();
Connection connection = null;
String driver;
String username;
String password;
String url;
try {
InputStream in = Object.class.getResourceAsStream("/bm.properties");
pro.load(in);
username = pro.getProperty("username");
password = pro.getProperty("password");
url = pro.getProperty("url");
driver = pro.getProperty("driver");
Class.forName(driver);
connection = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
e.printStackTrace();
}
return connection;
} 展开
Properties pro = new Properties();
Connection connection = null;
String driver;
String username;
String password;
String url;
try {
InputStream in = Object.class.getResourceAsStream("/bm.properties");
pro.load(in);
username = pro.getProperty("username");
password = pro.getProperty("password");
url = pro.getProperty("url");
driver = pro.getProperty("driver");
Class.forName(driver);
connection = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
e.printStackTrace();
}
return connection;
} 展开
2017-10-10
展开全部
配置文件拷贝到.class的目录。
~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
追问
试过不行
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询