當前位置: 首頁>>代碼示例>>Java>>正文


Java BasicDataSource.setDriverClassName方法代碼示例

本文整理匯總了Java中org.apache.commons.dbcp2.BasicDataSource.setDriverClassName方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicDataSource.setDriverClassName方法的具體用法?Java BasicDataSource.setDriverClassName怎麽用?Java BasicDataSource.setDriverClassName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.dbcp2.BasicDataSource的用法示例。


在下文中一共展示了BasicDataSource.setDriverClassName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: herdDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
/**
 * Get a new herd data source based on an in-memory HSQLDB database. This data source is used for loading the configuration table as an environment property
 * source as well as for the JPA entity manager. It will therefore create/re-create the configuration table which is required for the former. It also
 * inserts required values for both scenarios.
 *
 * @return the test herd data source.
 */
@Bean
public static DataSource herdDataSource()
{
    // Create and return a data source that can connect directly to a JDBC URL.
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(org.h2.Driver.class.getName());
    basicDataSource.setUsername("");
    basicDataSource.setPassword("");
    basicDataSource.setUrl("jdbc:h2:mem:herdTestDb");

    // Create and populate the configuration table.
    // This is needed for all data source method calls since it is used to create the environment property source which happens before
    // JPA and other non-static beans are initialized.
    ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
    resourceDatabasePopulator.addScript(new ClassPathResource("createConfigurationTableAndData.sql"));
    DatabasePopulatorUtils.execute(resourceDatabasePopulator, basicDataSource); // This is what the DataSourceInitializer does.

    return basicDataSource;
}
 
開發者ID:FINRAOS,項目名稱:herd,代碼行數:27,代碼來源:DaoEnvTestSpringModuleConfig.java

示例2: getBasicDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
private static BasicDataSource getBasicDataSource(DatasourceConfiguration configuration) {
    BasicDataSource dbcpDataSource = new BasicDataSource();
    dbcpDataSource.setDriverClassName(configuration.getDriverClassname());
    dbcpDataSource.setUrl(configuration.getUrl());
    dbcpDataSource.setUsername(configuration.getUser());
    dbcpDataSource.setPassword(configuration.getPassword());

    // Enable statement caching (Optional)
    dbcpDataSource.setPoolPreparedStatements(true);
    dbcpDataSource.setValidationQuery("Select 1 ");
    dbcpDataSource.setMaxOpenPreparedStatements(50);
    dbcpDataSource.setLifo(true);
    dbcpDataSource.setMaxTotal(10);
    dbcpDataSource.setInitialSize(2);
    return dbcpDataSource;
}
 
開發者ID:drinkwater-io,項目名稱:drinkwater-java,代碼行數:17,代碼來源:DBCPSqlDataStore.java

示例3: getEntityManagerFactory

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
/**
 * Returns the singleton EntityManagerFactory instance for accessing the
 * default database.
 * 
 * @return the singleton EntityManagerFactory instance
 * @throws NamingException
 *             if a naming exception occurs during initialization
 * @throws SQLException
 *             if a database occurs during initialization
 * @throws IOException 
 */
public static synchronized EntityManagerFactory getEntityManagerFactory()
		throws NamingException, SQLException, IOException {
	if (entityManagerFactory == null) {
		InitialContext ctx = new InitialContext();
	    BasicDataSource ds = new BasicDataSource();
	    JsonNode credentials = readCredentialsFromEnvironment();
		ds.setDriverClassName(credentials.get("driver").asText());
	    ds.setUrl(credentials.get("url").asText());
	    ds.setUsername(credentials.get("user").asText());
	    ds.setPassword(credentials.get("password").asText());
		Map<String, Object> properties = new HashMap<String, Object>();
		properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, ds);
		entityManagerFactory = Persistence.createEntityManagerFactory(
				PERSISTENCE_UNIT_NAME, properties);
	}
	return entityManagerFactory;
}
 
開發者ID:AnujMehta07,項目名稱:cloud-employeeslistapp,代碼行數:29,代碼來源:JpaEntityManagerFactory.java

示例4: invokeGetDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public DataSource invokeGetDataSource() {
	BasicDataSource bds = new BasicDataSource();
	bds.setDriverClassName("com.mysql.jdbc.Driver");
	bds.setUrl("jdbc:mysql://127.0.0.1:3306/inst02");
	bds.setUsername("root");
	bds.setPassword("123456");
	bds.setMaxTotal(50);
	bds.setInitialSize(20);
	bds.setMaxWaitMillis(60000);
	bds.setMinIdle(6);
	bds.setLogAbandoned(true);
	bds.setRemoveAbandonedOnBorrow(true);
	bds.setRemoveAbandonedOnMaintenance(true);
	bds.setRemoveAbandonedTimeout(1800);
	bds.setTestWhileIdle(true);
	bds.setTestOnBorrow(false);
	bds.setTestOnReturn(false);
	bds.setValidationQuery("select 'x' ");
	bds.setValidationQueryTimeout(1);
	bds.setTimeBetweenEvictionRunsMillis(30000);
	bds.setNumTestsPerEvictionRun(20);
	return bds;
}
 
開發者ID:liuyangming,項目名稱:ByteTCC-sample,代碼行數:24,代碼來源:ConsumerConfig.java

示例5: main

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
/**
 * The main method.
 *
 * @param args the arguments
 */
public static void main(String[] args) {
		try {
			List<String> tableNames = Arrays.asList(args[0].split("[|]"));
			String targetFolder = args[1];
			String packageName = args[2];
	        String jdbcLogin = args[3];
	        String jdbcPassword = args[4];
	        String jdbcUrl = args[5];
	        String jdbcDriverClassName = args[6];
	        BasicDataSource ds = new BasicDataSource();
			ds.setDriverClassName(jdbcDriverClassName);
			ds.setUsername(jdbcLogin);
			ds.setPassword(jdbcPassword);
			ds.setUrl(jdbcUrl);
			ds.setDefaultAutoCommit(true);
			
			CreateBasicDaoVo generateVos = new CreateBasicDaoVo().setDs(ds).setTableNames(tableNames)
					.setPackageName(packageName).setTargetFolder(targetFolder).setJdbcDriverClassName(jdbcDriverClassName);
			generateVos.process();

		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}
 
開發者ID:petezybrick,項目名稱:iote2e,代碼行數:30,代碼來源:CreateBasicDaoVo.java

示例6: dbcp

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@SneakyThrows
private static CloseableDatasource dbcp(Config config) {
    int threads = config.getInt("threads");
    BasicDataSource dataSource = new BasicDataSource();

    dataSource.setDriverClassName(config.getString("driver"));
    dataSource.setUrl(config.getString("url"));

    dataSource.setUsername(config.getString("user"));
    dataSource.setPassword(config.getString("pwd"));

    dataSource.setInitialSize(threads);

    dataSource.setMinEvictableIdleTimeMillis(120 * 1000);//seconds

    DBCPCloseableDataSource ds = new DBCPCloseableDataSource(dataSource);
    return ds;
}
 
開發者ID:jamescross91,項目名稱:shyft-extractor,代碼行數:19,代碼來源:DatasourceBuilder.java

示例7: createDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public DataSource createDataSource() {
    final String driverClass = (String) dbConfig.get("javax.persistence.jdbc.driver");
    final String connectionUrl = (String) dbConfig.get("javax.persistence.jdbc.url");
    final String username = (String) dbConfig.get("javax.persistence.jdbc.user");
    final String password = (String) dbConfig.get("javax.persistence.jdbc.password");

    final BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(driverClass);
    ds.setUsername(username);
    ds.setPassword(password);
    ds.setUrl(connectionUrl);
    ds.setMinIdle(1);
    ds.setMaxIdle(2);

    return ds;
}
 
開發者ID:dadrus,項目名稱:jpa-unit,代碼行數:17,代碼來源:SqlDbConfiguration.java

示例8: setupDatabase

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@BeforeClass
public static void setupDatabase() throws Exception {
  InputStream inputStream = MMXTopicTagsResourceTest.class.getResourceAsStream("/test.properties");

  Properties testProperties = new Properties();
  testProperties.load(inputStream);

  String host = testProperties.getProperty("db.host");
  String port = testProperties.getProperty("db.port");
  String user = testProperties.getProperty("db.user");
  String password = testProperties.getProperty("db.password");
  String driver = testProperties.getProperty("db.driver");
  String schema = testProperties.getProperty("db.schema");

  String url = "jdbc:mysql://" + host + ":" + port + "/" + schema;

  ds = new BasicDataSource();
  ds.setDriverClassName(driver);
  ds.setUsername(user);
  ds.setPassword(password);
  ds.setUrl(url);

}
 
開發者ID:magnetsystems,項目名稱:message-server,代碼行數:24,代碼來源:MMXConfigurationTest.java

示例9: setupDatabase

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@BeforeClass
public static void setupDatabase() throws Exception {
  InputStream inputStream = DeviceDAOImplTest.class.getResourceAsStream("/test.properties");

  Properties testProperties = new Properties();
  testProperties.load(inputStream);

  String host = testProperties.getProperty("db.host");
  String port = testProperties.getProperty("db.port");
  String user = testProperties.getProperty("db.user");
  String password = testProperties.getProperty("db.password");
  String driver = testProperties.getProperty("db.driver");
  String schema = testProperties.getProperty("db.schema");

  String url = "jdbc:mysql://" + host + ":" + port + "/" + schema;

  ds = new BasicDataSource();
  ds.setDriverClassName(driver);
  ds.setUsername(user);
  ds.setPassword(password);
  ds.setUrl(url);

  DBTestUtil.setBasicDataSource(ds);

  generateRandomUserData();
}
 
開發者ID:magnetsystems,項目名稱:message-server,代碼行數:27,代碼來源:UserDAOImplTest.java

示例10: init

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@PostConstruct
/**
 * Creates security data-source to be used with the sample DB 
 */
public void init() {
       securityDataSource = new BasicDataSource();
       securityDataSource.setDriverClassName(com.mysql.jdbc.Driver.class.getName());
       securityDataSource.setUrl("jdbc:mysql://localhost:3306/java_one_2014");
       securityDataSource.setUsername("java_one");
       securityDataSource.setPassword("");
	securityDataSource.setInitialSize(5);
       securityDataSource.setMaxTotal(30);
       securityDataSource.setMaxIdle(15);
       securityDataSource.setMaxWaitMillis(3000);
       securityDataSource.setLogAbandoned(true);
       securityDataSource.setTestWhileIdle(true);
       securityDataSource.setTestOnBorrow(true);
       securityDataSource.setValidationQuery("select 1");
}
 
開發者ID:ishaigor,項目名稱:rest-retro-sample,代碼行數:20,代碼來源:PersistenceConfiguration.java

示例11: wrap

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
@Override
public DataSource wrap(final ReportDataSource rptDs) {
    try {
        final BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(rptDs.getDriverClass());
        dataSource.setUrl(rptDs.getJdbcUrl());
        dataSource.setUsername(rptDs.getUser());
        dataSource.setPassword(rptDs.getPassword());
        dataSource.setInitialSize(MapUtils.getInteger(rptDs.getOptions(), "initialSize", 3));
        dataSource.setMaxIdle(MapUtils.getInteger(rptDs.getOptions(), "maxIdle", 20));
        dataSource.setMinIdle(MapUtils.getInteger(rptDs.getOptions(), "minIdle", 1));
        dataSource.setLogAbandoned(MapUtils.getBoolean(rptDs.getOptions(), "logAbandoned", true));
        dataSource.setRemoveAbandonedTimeout(
            MapUtils.getInteger(rptDs.getOptions(), "removeAbandonedTimeout", 180));
        dataSource.setMaxWaitMillis(MapUtils.getInteger(rptDs.getOptions(), "maxWait", 1000));
        return dataSource;
    } catch (final Exception ex) {
        throw new RuntimeException("C3p0DataSourcePool Create Error", ex);
    }
}
 
開發者ID:xianrendzw,項目名稱:EasyReport,代碼行數:21,代碼來源:DBCP2DataSourcePool.java

示例12: getInitializedDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
private BasicDataSource getInitializedDataSource(MySQLConfig mySqlConfig) {

		BasicDataSource basicDataSource = new BasicDataSource();

		basicDataSource.setDriverClassName(mySqlConfig.getDriverClass());
		basicDataSource.setUrl(mySqlConfig.getUrl());
		basicDataSource.setUsername(mySqlConfig.getUsername());
		basicDataSource.setPassword(mySqlConfig.getPassword());
		
		basicDataSource.setRemoveAbandonedTimeout(mySqlConfig.getRemoveAbandonedTimeoutInSeconds());
		basicDataSource.setRemoveAbandonedOnBorrow(mySqlConfig.isAbleToRemoveAbandonedConnections());
		basicDataSource.setRemoveAbandonedOnMaintenance(mySqlConfig.isAbleToRemoveAbandonedConnections());

		// int maxValue = 100;
		// basicDataSource.setMaxIdle(maxValue);
		// basicDataSource.setMaxTotal(maxValue);

		return basicDataSource;
	}
 
開發者ID:granpanda,項目名稱:autheo,代碼行數:20,代碼來源:Autheo.java

示例13: setupDataSource

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
/**
 * TODO: write documentation
 * 
 * @throws ClassNotFoundException
 */
private void setupDataSource() throws ClassNotFoundException {

	// request classloader to load JDBC driver class
	Class.forName(jdbcDriverClassName);

	// prepare and configure data source
	dataSource = new BasicDataSource();
	dataSource.setDefaultAutoCommit(true);
	dataSource.setDriverClassName(jdbcDriverClassName);
	dataSource.setUsername(jdbcLogin);
	dataSource.setPassword(jdbcPass);
	dataSource.setUrl(jdbcUrl + jdbcSchema);
	dataSource.setValidationQuery("select 1");
	dataSource.setDefaultQueryTimeout(1000);
	dataSource.setMaxConnLifetimeMillis(100000);
}
 
開發者ID:rwth-acis,項目名稱:mobsos-surveys,代碼行數:22,代碼來源:SurveyService.java

示例14: SQLDatabase

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public SQLDatabase(SQLDatabaseType jdbcInfo, String username, String password, String database, String host,
		int port, String key) {

	// TODO: check parameters

	this.jdbcInfo = jdbcInfo;
	this.username = username;
	this.password = password;
	this.host = host;
	this.port = port;
	this.database = database;
	this.key = key;

	BasicDataSource ds = new BasicDataSource();
	String urlPrefix = jdbcInfo.getJDBCurl(this.host, this.database, this.port) + "?autoReconnect=true";
	ds.setUrl(urlPrefix);
	ds.setUsername(username);
	ds.setPassword(password);
	ds.setDriverClassName(jdbcInfo.getDriverName());
	ds.setMinIdle(5);
	ds.setMaxIdle(10);
	ds.setMaxOpenPreparedStatements(100);

	dataSource = ds;
	setValidationQuery();
}
 
開發者ID:rwth-acis,項目名稱:mobsos-query-visualization,代碼行數:27,代碼來源:SQLDatabase.java

示例15: initialize

import org.apache.commons.dbcp2.BasicDataSource; //導入方法依賴的package包/類
public static void initialize(String driverName, String driverUrl, String userName, String password) throws SQLException {
    dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driverName);
    dataSource.setUsername(userName);
    dataSource.setPassword(password);
    dataSource.setUrl(driverUrl);

    dataSource.setDefaultReadOnly(false);
    dataSource.setDefaultAutoCommit(false);

    // enable detection and logging of connection leaks
    dataSource.setRemoveAbandonedOnBorrow(true);
    dataSource.setRemoveAbandonedOnMaintenance(true);
    dataSource.setRemoveAbandonedTimeout(3600); // 1 hour
    dataSource.setLogAbandoned(true);
    dataSource.setMaxWaitMillis(60000);
    dataSource.setMaxTotal(20);

    INITDATE = new Date();
}
 
開發者ID:statsbiblioteket,項目名稱:licensemodule,代碼行數:21,代碼來源:LicenseModuleStorage.java


注:本文中的org.apache.commons.dbcp2.BasicDataSource.setDriverClassName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。