以前全是这么做的,不过是个配置文件不是xml
道理应该一样 private void init() {
FileInputStream is=null;
try{
if(System.getProperty("file.separator").equals("/"))
is= new FileInputStream("./config/db.properties");
else
is= new FileInputStream(".\\config\\db.properties");
}catch(FileNotFoundException e){
System.out.println("File db.properties not found");
}
Properties dbProps = new Properties();
try {
dbProps.load(is);
}
catch (Exception e) {
System.err.println("Can't read the properties file. " +
"Make sure db.properties is in the CLASSPATH");
return;
}
logFile = dbProps.getProperty("logFile", "DBConnectionManager.log");
loadDrivers(dbProps);
createPools(dbProps);
}
道理应该一样 private void init() {
FileInputStream is=null;
try{
if(System.getProperty("file.separator").equals("/"))
is= new FileInputStream("./config/db.properties");
else
is= new FileInputStream(".\\config\\db.properties");
}catch(FileNotFoundException e){
System.out.println("File db.properties not found");
}
Properties dbProps = new Properties();
try {
dbProps.load(is);
}
catch (Exception e) {
System.err.println("Can't read the properties file. " +
"Make sure db.properties is in the CLASSPATH");
return;
}
logFile = dbProps.getProperty("logFile", "DBConnectionManager.log");
loadDrivers(dbProps);
createPools(dbProps);
}
但事实上这样很难,用oracle数据库的时候,里面有好多函数,如果用程序来写复杂多了。这样如果数据库不变,只变ip,还可以
你好!
db.properties这个文件放在哪个目录下?
你以上是applet格式吧!