当前位置: 首页>>代码示例>>Java>>正文


Java DriverManagerConnectionFactory类代码示例

本文整理汇总了Java中org.apache.commons.dbcp.DriverManagerConnectionFactory的典型用法代码示例。如果您正苦于以下问题:Java DriverManagerConnectionFactory类的具体用法?Java DriverManagerConnectionFactory怎么用?Java DriverManagerConnectionFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DriverManagerConnectionFactory类属于org.apache.commons.dbcp包,在下文中一共展示了DriverManagerConnectionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: DBManager

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
public DBManager() {
 ResourceBundle rb = PropertyResourceBundle.getBundle(
    "com.gint.app.bisisadmin.Config");
 String driver     = rb.getString("driver");
 String URL        = rb.getString("url");
 String username   = rb.getString("username");
 String password   = rb.getString("password");
	
 try {
   Class.forName(driver);
   GenericObjectPool connectionPool = new GenericObjectPool(null);
   DriverManagerConnectionFactory connectionFactory = 
     new DriverManagerConnectionFactory(URL, username, password);
   PoolableConnectionFactory poolableConnectionFactory =
     new PoolableConnectionFactory(connectionFactory, connectionPool, null, 
         null, false, false);
   poolingDataSource = new PoolingDataSource(connectionPool);
 } catch (Exception ex) {
   ex.printStackTrace();
 }  
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:22,代码来源:DBManager.java

示例2: main

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  Class.forName("com.mysql.jdbc.Driver");
  GenericObjectPool connectionPool = new GenericObjectPool(null);
  DriverManagerConnectionFactory connectionFactory = 
    new DriverManagerConnectionFactory("jdbc:mysql://localhost/bisis35?characterEncoding=UTF-8", 
        "bisis35", "bisis35");
  PoolableConnectionFactory poolableConnectionFactory =
    new PoolableConnectionFactory(connectionFactory, connectionPool, null, 
        null, false, true);
  PoolingDataSource poolingDataSource = new PoolingDataSource(connectionPool);
  
  RecordManagerImpl recMgr = new RecordManagerImpl();
  recMgr.setDataSource(poolingDataSource);
  
  Record rec1 = recMgr.getRecord(1);
  
  System.out.println(rec1);
}
 
开发者ID:unsftn,项目名称:bisis-v4,代码行数:19,代码来源:RetrieverTest.java

示例3: ConnectionPooling

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
/**
 * Constructor 
 *
 * Params:
 *
 *
 */
public ConnectionPooling(String connectionURL, String userName, String password, String driverName) throws ClassNotFoundException, SQLException{
	Class.forName(driverName);
	
	Properties props = new Properties();
	props.setProperty("user", userName);
	props.setProperty("password", password);
	
	ObjectPool connectionPool = new GenericObjectPool(null);
	
	ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectionURL, props);
	
	PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, 
			connectionPool, null, null, false, true);
	
	
	Class.forName("org.apache.commons.dbcp.PoolingDriver");
       PoolingDriver driver = (PoolingDriver) DriverManager.getDriver(myPoolingDriverName);
       driver.registerPool(myPoolName,connectionPool);
}
 
开发者ID:claresco,项目名称:Tinman,代码行数:27,代码来源:ConnectionPooling.java

示例4: buildDataSource

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
public static DataSource buildDataSource(String user, String pass,
        String driver, String url) {

    DataSource ds;

    try {
        Class.forName(driver);
    } catch (ClassNotFoundException ignore) {
    }

    GenericObjectPool connectionPool = new GenericObjectPool(null);
  ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
                      url, user, pass);
          PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
                      connectionFactory, connectionPool, null, null, false, true);

  return new PoolingDataSource(connectionPool);
}
 
开发者ID:apache,项目名称:oodt,代码行数:19,代码来源:DatabaseConnectionBuilder.java

示例5: getDataSource

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
private DataSource getDataSource(LinkDataSource lds){
	try{
		String driver, url, user, passwd;
		String[] access = lds.getAccess().split(",");
		driver = access[0];
		url = access[1];
		user = access[2];
		passwd = access[3];
		
		Class.forName(driver);
		
		ObjectPool connectionPool = new GenericObjectPool(null);
        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(url, user, passwd);
        PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
        PoolingDataSource data_source = new PoolingDataSource(connectionPool);
        
        return data_source;
	}
	catch(Exception e){
		
	}
	
	return null;
}
 
开发者ID:openmrs,项目名称:openmrs-module-patientmatching,代码行数:25,代码来源:ReaderProvider.java

示例6: setup

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
public void setup( Properties prop ) {
	this.prop=prop;

       GenericObjectPool.Config conPoolCfg = new GenericObjectPool.Config();
       conPoolCfg.maxActive = Integer.parseInt( prop.getProperty( "connectionPoolMaxSize", "15" ) );
       conPoolCfg.maxIdle = Integer.parseInt( prop.getProperty( "connectionPoolMaxIdle", "8" ) );
       conPoolCfg.maxWait = Integer.parseInt( prop.getProperty( "connectionPoolMaxWait", "60000" ) );
       conPoolCfg.minIdle = Integer.parseInt( prop.getProperty( "connectionPoolMinSize", "2" ) );


       ObjectPool connectionPool = new GenericObjectPool( null, conPoolCfg );
       try {
		Class.forName( prop.getProperty( "jdbcDriver" ) );
	} catch( ClassNotFoundException e ) {
		e.printStackTrace();
		throw new RuntimeException();
	}

       ConnectionFactory connectionFactory = new
           DriverManagerConnectionFactory( prop.getProperty( "jdbcUrl" ),
                                          prop.getProperty( "jdbcUser" ), 
                                          prop.getProperty( "jdbcPassword" ) );


       new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);

       PoolingDataSource dataSource = new PoolingDataSource(connectionPool);
       
       ds = dataSource;
}
 
开发者ID:yswang0927,项目名称:ralasafe,代码行数:31,代码来源:DataSourceProviderDbcpImpl.java

示例7: ReportDatasource

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
/**
 * Construct with configuration.
 *
 * @param configuration - app configuration
 */
public ReportDatasource (final Configuration configuration) {
    Optional<String> optConnectionURI = configuration.getJDBCConnectionString();
    if (!optConnectionURI.isPresent()) {
        dataSource = Optional.empty();
        return;
    }
    String connectionURI = optConnectionURI.get();
    ConnectionFactory cf = new DriverManagerConnectionFactory(connectionURI, null);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(cf, new GenericObjectPool(),
                    null, null, true, false);
    GenericObjectPool connectionPool = new GenericObjectPool(poolableConnectionFactory);
    dataSource = Optional.of(new PoolingDataSource(connectionPool));
}
 
开发者ID:jonmbake,项目名称:reports-micro-service,代码行数:19,代码来源:ReportDatasource.java

示例8: initializeDataSource

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
/**
    * @param config
    * @throws SQLException
    */
private void initializeDataSource(Config config) {
       String user = config.getString(CONFIG_KEY_DB_USER);
       String password = config.getString(CONFIG_KEY_DB_PASSWORD);

       Properties params = new Properties();

       if (isNotEmpty(user) && isNotEmpty(password)) {
           params.put("user", user);
           params.put("password", password);
       }

       // ドライバのロード
       String driver = config.getString(CONFIG_KEY_DB_DRIVER);
       boolean loadSuccess = DbUtils.loadDriver(driver);
       if (!loadSuccess) {
           String message = "failed to load driver.";
           throw new RuntimeException(message);
       }

       // コネクションをプールするDataSource を作成する
       @SuppressWarnings("rawtypes")
	GenericObjectPool pool = new GenericObjectPool();
       // コネクションプールの設定を行う
       int  maxActive = config.getInt(CONFIG_KEY_DB_MAX_ACTIVE_CONN, 100);
       long maxWait   = Long.parseLong(config.getString(CONFIG_KEY_DB_WAIT, "-1"));
       pool.setMaxActive(maxActive);
       pool.setMaxIdle(maxActive);
       pool.setMaxWait(maxWait);

       driverUrl = config.getString(CONFIG_KEY_DB_URL);
       ConnectionFactory connFactory = new DriverManagerConnectionFactory(driverUrl, params);
       new PoolableConnectionFactory(connFactory, pool, null,
               null, // validationQuery
               false, // defaultReadOnly
               false); // defaultAutoCommit
       dataSource = new PoolingDataSource(pool);
   }
 
开发者ID:okinawaopenlabs,项目名称:of-patch-manager,代码行数:42,代码来源:ConnectionManagerJdbc.java

示例9: setUp

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
/**
 *
 * @return @throws Exception
 */
public DataSource setUp() throws Exception {
    /**
     * Load JDBC Driver class.
     */
    Class.forName(ConnectionPool.DRIVER).newInstance();

    /**
     * Creates an instance of GenericObjectPool that holds our pool of
     * connections object.
     */
    connectionPool = new GenericObjectPool();
    // set the max number of connections
    connectionPool.setMaxActive(connections);
    // if the pool is exhausted (i.e., the maximum number of active objects has been reached), the borrowObject() method should simply create a new object anyway
    connectionPool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);

    /**
     * Creates a connection factory object which will be used by the pool to
     * create the connection object. We pass the JDBC url info, username
     * and password.
     */
    ConnectionFactory cf = new DriverManagerConnectionFactory(
            ConnectionPool.URL,
            ConnectionPool.USERNAME,
            ConnectionPool.PASSWORD);

    /**
     * Creates a PoolableConnectionFactory that will wrap the connection
     * object created by the ConnectionFactory to add object pooling
     * functionality.
     */
    PoolableConnectionFactory pcf
            = new PoolableConnectionFactory(cf, connectionPool,
                    null, null, false, true);
    return new PoolingDataSource(connectionPool);
}
 
开发者ID:disit,项目名称:sce-backend,代码行数:41,代码来源:ConnectionPool.java

示例10: initConnection

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
public final static void initConnection(String address, String user, String password) throws ClassNotFoundException {
	Class.forName("com.mysql.jdbc.Driver");
	GenericObjectPool connectionPool = new GenericObjectPool(null);
	ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(address, user, password);
	KeyedObjectPoolFactory keyed_factory = new StackKeyedObjectPoolFactory();
	new PoolableConnectionFactory(connectionFactory, connectionPool, keyed_factory, null, false, true);
	ds = new PoolingDataSource(connectionPool);
}
 
开发者ID:sunenielsen,项目名称:tribaltrouble,代码行数:9,代码来源:DBUtils.java

示例11: setUp

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
public DataSource setUp() throws Exception {
	Class.forName(DBPool.DRIVER).newInstance(); //Load driver
	//Create pool
	connectionPool = new GenericObjectPool();
       connectionPool.setMaxActive(DBPool.POOL_SIZE);
       //Create factor
       ConnectionFactory cf = new DriverManagerConnectionFactory(DBPool.URL,DBPool.USER,DBPool.PASSWORD);
       //Create PoolableConnectionFactory
       PoolableConnectionFactory pcf =
               new PoolableConnectionFactory(cf, connectionPool,
                       null, null, false, true);
       return new PoolingDataSource(connectionPool);
}
 
开发者ID:curi0us,项目名称:mgops,代码行数:14,代码来源:DBPool.java

示例12: getDefaultDataSource

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
private static DataSource getDefaultDataSource(final String database) {
    final GenericObjectPool connectionPool = new GenericObjectPool(null, 5);
    final ConnectionFactory connectionFactory = new DriverManagerConnectionFactory("jdbc:mysql://localhost:3306/" + database, "cloud", "cloud");
    final PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true);
    return new PoolingDataSource(
            /* connectionPool */poolableConnectionFactory.getPool());
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:9,代码来源:TransactionLegacy.java

示例13: DataSourceWorkflowRepositoryFactory

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
/**
 * <p>
 * Default Constructor
 * </p>.
 */
public DataSourceWorkflowRepositoryFactory() throws WorkflowException {
    String jdbcUrl, user, pass, driver;

    jdbcUrl = System
            .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.url");
    user = System
            .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.user");
    pass = System
            .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.pass");
    driver = System
            .getProperty("org.apache.oodt.cas.workflow.repo.datasource.jdbc.driver");

    try {
        Class.forName(driver);
    } catch (ClassNotFoundException e) {
        throw new WorkflowException("Cannot load driver: " + driver);
    }

    GenericObjectPool connectionPool = new GenericObjectPool(null);
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
            jdbcUrl, user, pass);
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
            connectionFactory, connectionPool, null, null, false, true);

    dataSource = new PoolingDataSource(connectionPool);
}
 
开发者ID:apache,项目名称:oodt,代码行数:32,代码来源:DataSourceWorkflowRepositoryFactory.java

示例14: setupDataSource

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
public static DataSource setupDataSource(String connectURI) {
    //
    // First, we'll need a ObjectPool that serves as the
    // actual pool of connections.
    //
    // We'll use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    //
    ObjectPool connectionPool = new GenericObjectPool(null);

    //
    // Next, we'll create a ConnectionFactory that the
    // pool will use to create Connections.
    // We'll use the DriverManagerConnectionFactory,
    // using the connect string passed in the command line
    // arguments.
    //
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURI,null);

    //
    // Now we'll create the PoolableConnectionFactory, which wraps
    // the "real" Connections created by the ConnectionFactory with
    // the classes that implement the pooling functionality.
    //
    PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);

    //
    // Finally, we create the PoolingDriver itself,
    // passing in the object pool we created.
    //
    PoolingDataSource dataSource = new PoolingDataSource(connectionPool);

    return dataSource;
}
 
开发者ID:WhiteBearSolutions,项目名称:WBSAirback,代码行数:35,代码来源:ManualPoolingDataSourceExample.java

示例15: setupDataSource

import org.apache.commons.dbcp.DriverManagerConnectionFactory; //导入依赖的package包/类
private DataSource setupDataSource(String driver, String connectURI,
                                   String userName, String passwd) throws ClassNotFoundException {

    // driver
    Class.forName(driver);

    //
    // First, we'll need a ObjectPool that serves as the
    // actual pool of connections.
    //
    // We'll use a GenericObjectPool instance, although
    // any ObjectPool implementation will suffice.
    //
    GenericObjectPool connectionPool = new GenericObjectPool(null);
    // 设置在getConnection时验证Connection是否有效
    connectionPool.setTestOnBorrow(true);

    //
    // Next, we'll create a ConnectionFactory that the
    // pool will use to create Connections.
    // We'll use the DriverManagerConnectionFactory,
    // using the connect string passed in the command line
    // arguments.
    //
    ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
            connectURI, userName, passwd);

    // null can be used as parameter because this parameter is set in
    // PoolableConnectionFactory when creating a new PoolableConnection
    KeyedObjectPoolFactory statementPool = new GenericKeyedObjectPoolFactory(
            null);

    //
    // Now we'll create the PoolableConnectionFactory, which wraps
    // the "real" Connections created by the ConnectionFactory with
    // the classes that implement the pooling functionality.
    //
    new PoolableConnectionFactory(connectionFactory, connectionPool,
            statementPool, "select now()", false, true);

    //
    // Finally, we create the PoolingDriver itself,
    // passing in the object pool we created.
    //
    PoolingDataSource dataSource = new PoolingDataSource(connectionPool);

    return dataSource;
}
 
开发者ID:warlock-china,项目名称:wisp,代码行数:49,代码来源:DbWrapper.java


注:本文中的org.apache.commons.dbcp.DriverManagerConnectionFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。