62,626
社区成员
发帖
与我相关
我的任务
分享
public class DbConfig {
private String id;
private String database;
private String driver;
private String login;
private String password;
private DataSource dataSource;
public String getDatabase() {
return database;
}
public void setDatabase(String database) {
database = Utility.replaceAllOccurances(database, "%dbpath%", Paths.getDbFolder());
this.database = database;
}
public String getDriver() {
return driver;
}
public void setDriver(String driver) {
this.driver = driver;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
/**
* Returns the data source or creates a new one.
* @return
*/
public DataSource getDataSource() {
if (dataSource == null) {
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(driver);
ds.setUsername(login);
ds.setPassword(password);
ds.setUrl(database);
// ds.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
ds.setInitialSize(10);
ds.setMaxActive(20);
ds.setMaxIdle(20);
ds.setMaxWait(5000);
dataSource = ds;
}
return dataSource;
}
<XXX-config>
<common-params>
<charset>utf-8</charset>
</common-params>
<db-config>
<db>
<id>file</id>
<database>jdbc:mysql://localhost:3306/chat</database>
<driver>com.mysql.jdbc.Driver</driver>
<login>root</login>
<password>!!!!please set this!!!!</password>
</db>
</db-config>
<error-handling>
<resource-type>FILE</resource-type>
<resource-path>%respath%/error.properties</resource-path>
</error-handling>
</XXX-config>