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


Java BasicDataSource.setUsername方法代码示例

本文整理汇总了Java中org.apache.commons.dbcp2.BasicDataSource.setUsername方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDataSource.setUsername方法的具体用法?Java BasicDataSource.setUsername怎么用?Java BasicDataSource.setUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.dbcp2.BasicDataSource的用法示例。


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

示例1: dataSource

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
/**
 * The following bean configures the database connection. The 'url' property value of "jdbc:derby:directory:jpaserver_derby_files;create=true" indicates that the server should save resources in a
 * directory called "jpaserver_derby_files".
 * 
 * A URL to a remote database could also be placed here, along with login credentials and other properties supported by BasicDataSource.
 */
@Bean(destroyMethod = "close")
public DataSource dataSource() {
	BasicDataSource retVal = new BasicDataSource();
	/*
	retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver());
	retVal.setUrl("jdbc:derby:directory:target/jpaserver_derby_files;create=true");
	retVal.setUsername("");
	retVal.setPassword("");
	* */
	 
	
	try
	{
		retVal.setDriver(new com.mysql.jdbc.Driver());
	}
	catch (Exception exc)
	{
		exc.printStackTrace();
	}
	retVal.setUrl("jdbc:mysql://localhost:3306/dhis2_fhir");
	retVal.setUsername("root");
	retVal.setPassword("");
	return retVal;
}
 
开发者ID:gerard-bisama,项目名称:DHIS2-fhir-lab-app,代码行数:31,代码来源:FhirServerConfigDstu3.java

示例2: dataSource

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
/**
 * The following bean configures the database connection. The 'url' property value of "jdbc:derby:directory:jpaserver_derby_files;create=true" indicates that the server should save resources in a
 * directory called "jpaserver_derby_files".
 * 
 * A URL to a remote database could also be placed here, along with login credentials and other properties supported by BasicDataSource.
 */
@Bean(destroyMethod = "close")
public DataSource dataSource() {
	BasicDataSource retVal = new BasicDataSource();
	/*
	retVal.setDriver(new org.apache.derby.jdbc.EmbeddedDriver());
	retVal.setUrl("jdbc:derby:directory:target/jpaserver_derby_files;create=true");
	retVal.setUsername("");
	retVal.setPassword("");
	*/
	try
	{
		//retVal.setDriver(new com.mysql.jdbc.Driver());
		retVal.setDriver(new org.postgresql.Driver());
	}
	catch (Exception exc)
	{
		exc.printStackTrace();
	}
	//retVal.setUrl("jdbc:mysql://localhost:3306/dhis2_fhir");
	retVal.setUrl("jdbc:postgresql://localhost:5432/dhis2_fhir");
	retVal.setUsername("fhir");
	retVal.setPassword("xxxxxxx");
	
	return retVal;
}
 
开发者ID:gerard-bisama,项目名称:DHIS2-fhir-lab-app,代码行数:32,代码来源:FhirServerConfig.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: 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

示例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: 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

示例7: testOpenConnectionToH2DbHavingAllSupportedPersistenceProperties

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Test
public void testOpenConnectionToH2DbHavingAllSupportedPersistenceProperties() throws ClassNotFoundException {
    // GIVEN
    final BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(H2_DRIVER_CLASS_PROP_VALUE);
    ds.setUsername(USERNAME_PROP_VALUE);
    ds.setPassword(PASSWORD_PROP_VALUE);
    ds.setUrl(H2_CONNECTION_URL_PROP_VALUE);

    // WHEN
    connection = DatabaseConnectionFactory.openConnection(ds);

    // THEN
    assertThat(connection, notNullValue());
    assertThat(connection, instanceOf(H2Connection.class));
}
 
开发者ID:dadrus,项目名称:jpa-unit,代码行数:17,代码来源:DatabaseConnectionFactoryTest.java

示例8: 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

示例9: TestOpenfireConnectionProvider

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
public TestOpenfireConnectionProvider() 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,代码行数:22,代码来源:TestOpenfireConnectionProvider.java

示例10: setDataSourceFromPropertyFile

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
public static void setDataSourceFromPropertyFile() 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);
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:22,代码来源:DBTestUtil.java

示例11: getDataSource

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
@Bean
public BasicDataSource getDataSource() throws URISyntaxException {
	String url = System.getenv("DATABASE_URL");
	if (url == null) {
		url = "mysql://bugminer:[email protected]:3306/bugminer";
	}

	URI dbUri = new URI(url);
	String username = dbUri.getUserInfo().split(":")[0];
	String password = dbUri.getUserInfo().split(":")[1];
	String scheme = dbUri.getScheme();
	if (scheme.equals("postgres")) {
		scheme = "postgresql";
	}
	String dbUrl = "jdbc:" + scheme + "://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath();

	BasicDataSource basicDataSource = new BasicDataSource();
	basicDataSource.setUrl(dbUrl);
	basicDataSource.setUsername(username);
	basicDataSource.setPassword(password);

	return basicDataSource;
}
 
开发者ID:bugminer,项目名称:bugminer,代码行数:24,代码来源:AppConfig.java

示例12: main

import org.apache.commons.dbcp2.BasicDataSource; //导入方法依赖的package包/类
public static void main(String[] args) 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;

  BasicDataSource ds = new BasicDataSource();
  ds.setDriverClassName(driver);
  ds.setUsername(user);
  ds.setPassword(password);
  ds.setUrl(url);
  TreeMap<String, String> map = new TreeMap<String, String>();
  map.put("mmxTag", "SELECT * FROM mmxTag ");
  doWork(ds.getConnection(), map);
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:25,代码来源:DatabaseExport.java

示例13: 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

示例14: 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);
  generatePubsubItems();
}
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:26,代码来源:TopicItemDAOImplTest.java

示例15: 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


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