当前位置: 技术问答>java相关
连接池出错:Can not read the properties file; Make sure db.properties is in the Classpath
来源: 互联网 发布时间:2015-10-22
本文导语: weblogic下连接池配置好可以用了。。后来想用db.properties配置,结果说: Can not read the properties file; Make sure db.properties is in the Classpath 我的DBConnectionManager.java部分代码: /** * 读取属性完成初始化 */ private void i...
weblogic下连接池配置好可以用了。。后来想用db.properties配置,结果说:
Can not read the properties file; Make sure db.properties is in the Classpath
我的DBConnectionManager.java部分代码:
/**
* 读取属性完成初始化
*/
private void init() {
InputStream is = getClass().getResourceAsStream("db.properties");
Properties dbProps = new Properties();
try {
dbProps.load(is);
}
catch (Exception e) {
System.err.println("Can not read the properties file; " + "Make sure db.properties is in the Classpath");
return;
}
String logFile = dbProps.getProperty("logfile", "DBConnectionManager.log");
try {
log = new PrintWriter(new FileWriter(logFile, true), true);
}
catch (IOException e) {
System.err.println("Can not open the log files: " + logFile);
log = new PrintWriter(System.err);
}
loadDrivers(dbProps);
createPools(dbProps);
}
我的db.properties:
drivers=sun.jdbc.odbc.JdbcOdbcDriver
logfile=D:\log.txt
denis.url=jdbc:odbc:denis
denis.maxconn=1000
denis.user=another
denis.password=another()
谢谢大家。
Can not read the properties file; Make sure db.properties is in the Classpath
我的DBConnectionManager.java部分代码:
/**
* 读取属性完成初始化
*/
private void init() {
InputStream is = getClass().getResourceAsStream("db.properties");
Properties dbProps = new Properties();
try {
dbProps.load(is);
}
catch (Exception e) {
System.err.println("Can not read the properties file; " + "Make sure db.properties is in the Classpath");
return;
}
String logFile = dbProps.getProperty("logfile", "DBConnectionManager.log");
try {
log = new PrintWriter(new FileWriter(logFile, true), true);
}
catch (IOException e) {
System.err.println("Can not open the log files: " + logFile);
log = new PrintWriter(System.err);
}
loadDrivers(dbProps);
createPools(dbProps);
}
我的db.properties:
drivers=sun.jdbc.odbc.JdbcOdbcDriver
logfile=D:\log.txt
denis.url=jdbc:odbc:denis
denis.maxconn=1000
denis.user=another
denis.password=another()
谢谢大家。
|
引用db.properties,如果不可以!
请检查你的属性文件
或者在classpath下引用一下!!不一定好用!但是可以试试!
还有!就是目录要一致。
请检查你的属性文件
或者在classpath下引用一下!!不一定好用!但是可以试试!
还有!就是目录要一致。