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


Java HikariDataSource.setUsername方法代码示例

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


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

示例1: testConnection

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Override
public void testConnection(String driverClass, String jdbcUrl, String username, String password)
{
	try
	{
		HikariDataSource source = new HikariDataSource();
		source.setDriverClassName(driverClass);
		source.setJdbcUrl(jdbcUrl);
		source.setUsername(username);
		source.setPassword(password);
		source.setMaximumPoolSize(1);

		String testQuery = "SELECT COUNT(*) FROM "
			+ (jdbcUrl.startsWith("jdbc:oracle") ? "ALL_TABLES" : "information_schema.tables");
		new JdbcTemplate(source).query(testQuery, IGNORE_ROWS);

		source.close();
	}
	catch( Exception ex )
	{
		LOGGER.warn("Test connection failure", ex);
		Throwable rootCause = Throwables.getRootCause(ex);
		throw new RuntimeException("Error attempting to connect or while executing test query: "
			+ rootCause.getMessage());
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:27,代码来源:RemoteSqlQueryingServiceImpl.java

示例2: openConnectionPool

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
private static void openConnectionPool(String url, String driverClass, String username, String password) throws Exception {

        //force the driver to be loaded
        Class.forName(driverClass);

        HikariDataSource pool = new HikariDataSource();
        pool.setJdbcUrl(url);
        pool.setUsername(username);
        pool.setPassword(password);
        pool.setMaximumPoolSize(4);
        pool.setMinimumIdle(1);
        pool.setIdleTimeout(60000);
        pool.setPoolName("Hl7MergeCheckerPool" + url);
        pool.setAutoCommit(false);

        connectionPool = pool;

        //test getting a connection
        Connection conn = pool.getConnection();
        conn.close();
    }
 
开发者ID:endeavourhealth,项目名称:HL7Receiver,代码行数:22,代码来源:Main.java

示例3: initialiseDBConnectionPool

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
private synchronized void initialiseDBConnectionPool() throws ConfigurationException {
    try {
        if (this.dataSource == null) {

            HikariDataSource hikariDataSource = new HikariDataSource();
            hikariDataSource.setJdbcUrl(postgresUrl);
            hikariDataSource.setUsername(postgresUsername);
            hikariDataSource.setPassword(postgresPassword);
            hikariDataSource.setDriverClassName("org.postgresql.Driver");
            hikariDataSource.setMaximumPoolSize(15);
            hikariDataSource.setMinimumIdle(2);
            hikariDataSource.setIdleTimeout(60000);
            hikariDataSource.setConnectionTimeout(5000L);
            hikariDataSource.setPoolName("HL7ReceiverDBConnectionPool");

            this.dataSource = hikariDataSource;
        }
    } catch (Exception e) {
        throw new ConfigurationException("Error creating Hikari connection pool", e);
    }
}
 
开发者ID:endeavourhealth,项目名称:HL7Receiver,代码行数:22,代码来源:Configuration.java

示例4: createHikariDataSource

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
private HikariDataSource createHikariDataSource(JdbcProperties jdbcProperties) {
  HikariDataSource hikariDataSource = new HikariDataSource();
  hikariDataSource.setJdbcUrl(jdbcProperties.getJdbcUrl());
  hikariDataSource.setUsername(jdbcProperties.getUsername());
  hikariDataSource.setPassword(jdbcProperties.getPassword());

  JdbcPoolProperties jdbcPoolProperties = jdbcProperties.getJdbcPool();
  hikariDataSource.setAutoCommit(jdbcPoolProperties.isAutoCommit());
  hikariDataSource.setConnectionTimeout(jdbcPoolProperties.getConnectionTimeout());
  hikariDataSource.setIdleTimeout(jdbcPoolProperties.getIdleTimeout());
  hikariDataSource.setMaxLifetime(jdbcPoolProperties.getMaxLifetime());
  hikariDataSource.setMaximumPoolSize(jdbcPoolProperties.getMaximumPoolSize());
  hikariDataSource.setMinimumIdle(jdbcPoolProperties.getMinimumIdle());
  hikariDataSource
      .setInitializationFailTimeout(jdbcPoolProperties.getInitializationFailTimeout());
  hikariDataSource.setIsolateInternalQueries(jdbcPoolProperties.isIsolateInternalQueries());
  hikariDataSource.setReadOnly(jdbcPoolProperties.isReadOnly());
  hikariDataSource.setRegisterMbeans(jdbcPoolProperties.isRegisterMbeans());
  Optional.ofNullable(jdbcPoolProperties.getDriverClassName())
      .ifPresent(hikariDataSource::setDriverClassName);
  hikariDataSource.setValidationTimeout(jdbcPoolProperties.getValidationTimeout());
  hikariDataSource.setLeakDetectionThreshold(jdbcPoolProperties.getLeakDetectionThreshold());
  return hikariDataSource;
}
 
开发者ID:lord-of-code,项目名称:loc-framework,代码行数:25,代码来源:LocDataSourceAutoConfiguration.java

示例5: connect

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
public void connect() {
    dataSource = new HikariDataSource();
    dataSource.setJdbcUrl(this.jdbcUrl);
    dataSource.setUsername(this.username);
    dataSource.setPassword(this.password);

    if (!doesTableExist("player_addresses")) {
        try (Connection connection = getConnection()) {
            PreparedStatement statement = connection.prepareStatement("CREATE TABLE player_addresses (`uuid` CHAR(36) PRIMARY KEY, `address` VARCHAR(20));");
            statement.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:me4502,项目名称:AdvancedServerListIcons,代码行数:16,代码来源:DatabaseManager.java

示例6: buildH2Datasource

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
private static HikariDataSource buildH2Datasource() {
	HikariDataSource ds = new HikariDataSource();
	ds.addDataSourceProperty("cachePrepStmts", true);
	ds.addDataSourceProperty("prepStmtCacheSize", 250);
	ds.addDataSourceProperty("prepStmtCacheSqlLimit", 2048);
	ds.addDataSourceProperty("useServerPrepStmts", true);
	ds.setMaximumPoolSize(3);
	ds.setConnectionTimeout(5000);
	ds.setJdbcUrl("jdbc:h2:mem:DBName;MODE=MYSQL;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=0");
	ds.setDriverClassName("org.h2.Driver");
	ds.setUsername("sa");
	ds.setPassword("");
	return ds;
}
 
开发者ID:drinkjava2,项目名称:jDialects,代码行数:15,代码来源:DialectTest.java

示例7: initialise

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Override
protected boolean initialise(UserManagementSettings settings)
{
	config = (ReplicatedConfiguration) settings;

	source = new HikariDataSource();
	source.setDriverClassName(config.getDriver());
	source.setUsername(config.getUsername());
	source.setPassword(config.getPassword());
	source.setJdbcUrl(config.getUrl());
	jdbcTemplate = new JdbcTemplate(source);

	return false;
}
 
开发者ID:equella,项目名称:Equella,代码行数:15,代码来源:ReplicatedUserPlugin.java

示例8: primaryDataSource

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Bean
public DataSource primaryDataSource() {
    HikariDataSource ds = new HikariDataSource();
    ds.setMaximumPoolSize(100);
    ds.setMinimumIdle(30);
    ds.setDriverClassName("org.h2.Driver");
    ds.setJdbcUrl("jdbc:h2:mem:test");
    ds.setUsername("root");
    ds.setPassword("root");
    return ds;
}
 
开发者ID:SkywalkingTest,项目名称:CNUTCon-2017-Demo,代码行数:12,代码来源:DataSourceConfig.java

示例9: PostgreStorage

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
public PostgreStorage(String url, String username, String password) {
  HikariDataSource ds = new HikariDataSource();
  ds.setJdbcUrl(url);
  ds.setUsername(username);
  ds.setPassword(password);
  this.dbi = new DBI(ds);
  createTables();
}
 
开发者ID:longkerdandy,项目名称:qfii-tracker,代码行数:9,代码来源:PostgreStorage.java

示例10: getDSLContext

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Bean
public DSLContext getDSLContext() {
	HikariDataSource hikariDataSource = new HikariDataSource();
	hikariDataSource.setJdbcUrl(environment.getProperty("spring.datasource.url"));
	hikariDataSource.setUsername(environment.getProperty("spring.datasource.username"));
	hikariDataSource.setPassword(environment.getProperty("spring.datasource.password"));
	ConnectionProvider connectionProvider = new DataSourceConnectionProvider(hikariDataSource);
	org.jooq.Configuration configuration = new DefaultConfiguration().set(connectionProvider).set(SQLDialect.MYSQL);
	return DSL.using(configuration);
}
 
开发者ID:Sunshine-Constructing,项目名称:sunshine-security,代码行数:11,代码来源:DSLConfig.java

示例11: prepareSql2o

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
private static Sql2o prepareSql2o(final Configuration config) {
	final HikariDataSource ds = new HikariDataSource();
	ds.setJdbcUrl(config.getDatabase().getUrl());
	ds.setUsername(config.getDatabase().getUser());
	ds.setPassword(config.getDatabase().getPassword());
	//fix for not auto-detecting driver when running local demo on mac
	if (config.getDatabase().getUrl().contains("jdbc:hsqldb:mem:"))
		ds.setDriverClassName("org.hsqldb.jdbc.JDBCDriver");
	return new Sql2o(ds);
}
 
开发者ID:hellrich,项目名称:JeSemE,代码行数:11,代码来源:CLI.java

示例12: DatabaseServiceHelper

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
public DatabaseServiceHelper() throws Exception {
	final Configuration config = Configuration
			.readYamlFile("src/test/resources/config.yaml");
	ds = new HikariDataSource();
	ds.setJdbcUrl(config.getDatabase().getUrl());
	ds.setUsername(config.getDatabase().getUser());
	ds.setPassword(config.getDatabase().getPassword());

	final Sql2o sql2o = new Sql2o(ds);

	DatabaseService.initializeTables(sql2o);
	DatabaseService.importTables(config, sql2o);
	db = new DatabaseService(sql2o, config);
}
 
开发者ID:hellrich,项目名称:JeSemE,代码行数:15,代码来源:DatabaseServiceHelper.java

示例13: doTest

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Test
public void doTest() {
	HikariDataSource dataSource = new HikariDataSource();// DataSource

	// H2 is a memory database
	dataSource.setDriverClassName("org.h2.Driver");
	dataSource.setJdbcUrl("jdbc:h2:mem:DBName;MODE=MYSQL;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=0");
	dataSource.setUsername("sa");
	dataSource.setPassword("");

	// MySQL
	// dataSource.setDriverClassName("com.mysql.jdbc.Driver");
	// dataSource.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?rewriteBatchedStatements=true&useSSL=false");
	// dataSource.setUsername("root");
	// dataSource.setPassword("root888");

	// MS-SqlServer
	// dataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	// dataSource.setJdbcUrl("jdbc:sqlserver://localhost:1433;databaseName=test");
	// dataSource.setUsername("sa");
	// dataSource.setPassword("root888");

	// ORACLE
	// dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
	// dataSource.setJdbcUrl("jdbc:oracle:thin:@127.0.0.1:1521:XE");
	// dataSource.setUsername("root");
	// dataSource.setPassword("root888");

	SqlBoxContext ctx = new SqlBoxContext(dataSource);
	SqlBoxContext.setDefaultContext(ctx);
	ctx.setAllowShowSQL(true);
	String[] ddlArray = ctx.toDropAndCreateDDL(User.class);
	for (String ddl : ddlArray)
		ctx.quiteExecute(ddl);
	for (int i = 1; i <= 100; i++)
		new User().put("firstName", "Foo" + i, "lastName", "Bar" + i, "age", i).insert();

	TransactionFactory transactionFactory = new JdbcTransactionFactory();
	Environment environment = new Environment("demo", transactionFactory, dataSource);
	Configuration configuration = new Configuration(environment);
	configuration.addMapper(UserMapper.class);
	SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
	configuration.addInterceptor(new JDialectsPlugin());

	SqlSession session = null;
	try {
		session = sqlSessionFactory.openSession();
		Connection conn = session.getConnection();
		Assert.assertEquals(100, ctx.nQueryForLongValue(conn, "select count(*) from users"));

		List<Map<String, Object>> users;
		try {
			paginInfo.set(new Object[] { ctx.getDialect(), 3, 10 });
			users = session.getMapper(UserMapper.class).getOlderThan(50);
		} finally {
			paginInfo.remove();
		}
		Assert.assertEquals(10, users.size());
		for (Map<String, Object> map : users)
			System.out.println("UserName=" + map.get("USERNAME") + ", age=" + map.get("AGE"));
	} finally {
		session.close();
	}
	dataSource.close();
}
 
开发者ID:drinkjava2,项目名称:jDialects,代码行数:66,代码来源:Demo.java

示例14: doTest

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Test
public void doTest() {
	HikariDataSource ds = new HikariDataSource();// DataSource

	// H2 is a memory database
	ds.setDriverClassName("org.h2.Driver");
	ds.setJdbcUrl("jdbc:h2:mem:DBName;MODE=MYSQL;DB_CLOSE_DELAY=-1;TRACE_LEVEL_SYSTEM_OUT=0");
	ds.setUsername("sa");
	ds.setPassword("");

	// MySQL
	// ds.setDriverClassName("com.mysql.jdbc.Driver");
	// ds.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?rewriteBatchedStatements=true&useSSL=false");
	// ds.setUsername("root");
	// ds.setPassword("root888");

	// MS-SqlServer
	// ds.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
	// ds.setJdbcUrl("jdbc:sqlserver://localhost:1433;databaseName=test");
	// ds.setUsername("sa");
	// ds.setPassword("root888");

	// ORACLE
	// ds.setDriverClassName("oracle.jdbc.OracleDriver");
	// ds.setJdbcUrl("jdbc:oracle:thin:@127.0.0.1:1521:XE");
	// ds.setUsername("root");
	// ds.setPassword("root888");

	SqlBoxContext ctx = new SqlBoxContext(ds);
	SqlBoxContext.setDefaultContext(ctx);
	// ctx.setAllowShowSQL(true);

	String[] ddlArray = ctx.toDropAndCreateDDL(User.class);
	for (String ddl : ddlArray)
		ctx.quiteExecute(ddl);

	for (int i = 1; i <= 100; i++) {
		User u = new User();
		u.setFirstName("Foo" + i);
		u.setLastName("Bar" + i);
		u.setAge(i);
		u.insert();
	}
	Assert.assertEquals(100, ctx.nQueryForLongValue("select count(*) from users"));

	List<Map<String, Object>> users = ctx.nQueryForMapList(ctx.paginate(2, 10,
			"select concat(firstName, ' ', lastName) as USERNAME, age from users where age>?"), 50);

	Assert.assertEquals(10, users.size());

	for (Map<String, Object> map : users)
		System.out.println("UserName=" + map.get("USERNAME") + ", age=" + map.get("AGE"));

	ds.close();
}
 
开发者ID:drinkjava2,项目名称:jDialects,代码行数:56,代码来源:Demo.java

示例15: register

import com.zaxxer.hikari.HikariDataSource; //导入方法依赖的package包/类
@Override
public boolean register() {
    if (IsRegistered) {
        return HAS_REGISTERED;
    }

    HikariDataSource ds = new HikariDataSource();

    //basic config
    ds.setJdbcUrl(jdbcURL);
    ds.setDriverClassName(jdbcDriver);
    ds.setUsername(jdbcUsername);
    ds.setPassword(jdbcPassword);

    //custom config
    ds.setAutoCommit(autoCommit);
    ds.setConnectionTimeout(connectionTimeout);
    ds.setIdleTimeout(idleTimeout);
    ds.setMaxLifetime(maxLifetime);
    ds.setMaximumPoolSize(maximumPoolSize);
    ds.setValidationTimeout(validationTimeout);
    ds.setLeakDetectionThreshold(leakDetectionThreshold);

    if (!StrUtil.isBlank(poolName)) {
        ds.setPoolName(poolName);
    }

    if (!StrUtil.isBlank(catalog)) {
        ds.setCatalog(catalog);
    }

    if (!StrUtil.isBlank(connectionInitSql)) {
        ds.setConnectionInitSql(connectionInitSql);
    }

    if (!StrUtil.isBlank(transactionIsolation)) {
        ds.setTransactionIsolation(transactionIsolation);
    }

    if (jdbcURL.contains(":mysql:")) {
        ds.addDataSourceProperty("cachePrepStmts", "true");
        ds.addDataSourceProperty("prepStmtCacheSize", "250");
        ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
        ds.addDataSourceProperty("useServerPrepStmts", "true");
    }

    setDataSource(ds);
    setIsRegistered(HAS_REGISTERED);
    return HAS_REGISTERED;
}
 
开发者ID:xujiajun,项目名称:tastjava,代码行数:51,代码来源:HikariCPProvider.java


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