DB.properties
#HSQLDB Configer
HSQL_USERNAME=sa
HSQL_PASSWORD=
HSQL_DRIVERNAME=org.hsqldb.jdbcDriver
HSQL_URL=jdbc:hsqldb:hsql://localhost/test
ReadProperties.java
package org.test;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
public class ReadProperties {
public static Logger loggetLogger(ReadProperties.class);
static Properties p = null;
public ReadProperties() {
InputStream is = this.getClass().getClassLoader().getResourceAsStream(
"DB.properties");
p = new Properties();
try {
// InputStream is = new BufferedInputStream(new
// FileInputStream("./src/DB.properties"));
p.load(is);
} catch (IOException e1) {
log.error(e1);
}
}
/**
*
*/
public static String[] getHSQLINFO() {
new ReadProperties();
String[] value = new String[4];
value[0] = p.getProperty("HSQL_USERNAME");
value[1] = p.getProperty("HSQL_PASSWORD");
value[2] = p.getProperty("HSQL_DRIVERNAME");
value[3] = p.getProperty("HSQL_URL");
return value;
}
/**
*
* 概述:
* @Title: getConnInfo
* @param userName
* @param passWord
* @param driverName
* @param url
* @return
* String[]
* @user <a href=mailto:linfenliang@126.com>linfenliang</a>
*/
public static String[] getConnInfo(String userName,String passWord,String driverName,String url){
new ReadProperties();
String[] value = new String[4];
value[0] = p.getProperty(userName);
value[1] = p.getProperty(passWord);
value[2] = p.getProperty(driverName);
value[3] = p.getProperty(url);
return value;
}
}