本文整理汇总了Java中org.apache.commons.dbcp.BasicDataSourceFactory类的典型用法代码示例。如果您正苦于以下问题:Java BasicDataSourceFactory类的具体用法?Java BasicDataSourceFactory怎么用?Java BasicDataSourceFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicDataSourceFactory类属于org.apache.commons.dbcp包,在下文中一共展示了BasicDataSourceFactory类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: __doInit
import org.apache.commons.dbcp.BasicDataSourceFactory; //导入依赖的package包/类
@Override
protected void __doInit() throws Exception {
Properties _props = new Properties();
InputStream _in = ResourceUtils.getResourceAsStream("dbcp.properties", this.getClass());
if (_in != null) {
_props.load(_in);
}
//
_props.put("driverClassName", __cfgMeta.getDriverClass());
_props.put("url", __cfgMeta.getConnectionUrl());
_props.put("username", __cfgMeta.getUsername());
if (StringUtils.isNotBlank(__cfgMeta.getPassword()) && __cfgMeta.isPasswordEncrypted() && __cfgMeta.getPasswordClass() != null) {
_props.put("password", __cfgMeta.getPasswordClass().newInstance().decrypt(__cfgMeta.getPassword()));
} else {
_props.put("password", __cfgMeta.getPassword());
}
__ds = (BasicDataSource) BasicDataSourceFactory.createDataSource(_props);
}
示例2: DbcpDataSource
import org.apache.commons.dbcp.BasicDataSourceFactory; //导入依赖的package包/类
private DbcpDataSource() throws Exception{
InputStream in = new FileInputStream(DbcpDataSource.class.getResource("/dbcp.properties").getPath());
Properties property = new Properties();
property.load(in);
// dataSource = BasicDataSourceFactory.createDataSource(property);
dataSource = (BasicDataSource)BasicDataSourceFactory.createDataSource(property);
}
示例3: init
import org.apache.commons.dbcp.BasicDataSourceFactory; //导入依赖的package包/类
/**
* 初始化连接池
*/
public void init() {
if (dataSource != null) {
try {
dataSource.close();
} catch (Exception ignored) {
}
dataSource = null;
}
try {
Properties p = new Properties();
p.setProperty("driverClassName", this.driverClassName);
p.setProperty("url", this.connectUrl);
p.setProperty("username", this.username);
p.setProperty("password", this.password);
p.setProperty("maxActive", this.maxActive);
p.setProperty("maxIdle", this.maxIdle);
p.setProperty("maxWait", this.maxWait);
p.setProperty("removeAbandoned", this.removeAbandoned);
p.setProperty("removeAbandonedTimeout", this.removeAbandonedTimeout);
p.setProperty("logAbandoned", "false");
// p.setProperty("testOnBorrow", "true");连接验证..先关掉吧
dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(p);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
示例4: createDataSource
import org.apache.commons.dbcp.BasicDataSourceFactory; //导入依赖的package包/类
/**
* Returns new Pooled {@link DataSource} implementation
*
* @param poolProperties pool properties
* @return new Pooled {@link DataSource} implementation
* @throws SQLException
*/
public static DataSource createDataSource(Properties poolProperties) throws SQLException {
assertNotNull(poolProperties);
try {
return BasicDataSourceFactory.createDataSource(poolProperties);
} catch (Exception e) {
throw new SQLException(e);
}
}
示例5: createDataSource
import org.apache.commons.dbcp.BasicDataSourceFactory; //导入依赖的package包/类
/**
* Returns new Pooled {@link DataSource} implementation
*
* @param poolProperties pool properties
* @return new Pooled {@link DataSource} implementation
* @throws SQLException
*/
public static DataSource createDataSource(Properties poolProperties) throws SQLException {
assertNotNull(poolProperties);
try {
return BasicDataSourceFactory.createDataSource(poolProperties);
} catch (Exception e) {
throw new SQLException(e.getMessage());
}
}
示例6: dataSource
import org.apache.commons.dbcp.BasicDataSourceFactory; //导入依赖的package包/类
@Bean
public DataSource dataSource() throws Exception {
return BasicDataSourceFactory.createDataSource(PoolProperties.createFromEnvironment(this.env));
}