Java Code Examples for com.mysql.cj.jdbc.MysqlDataSource#setDatabaseName()

The following examples show how to use com.mysql.cj.jdbc.MysqlDataSource#setDatabaseName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MySqlHelper.java    From cassandana with Apache License 2.0 6 votes vote down vote up
public synchronized void tryConnecting() {

		MysqlDataSource dataSource = new MysqlDataSource();
		dataSource.setServerName(this.host);
		dataSource.setPort(port);
		dataSource.setUser(this.dbUsername);
		dataSource.setPassword(this.dbPassword);
		dataSource.setDatabaseName(this.dbName);

		try {
			dataSource.setCharacterEncoding("utf-8");
			connection = dataSource.getConnection();

			setConnected(true);
			onConnected();
			System.out.println("connected to mysql server: " + host + ":" + port);

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
 
Example 2
Source File: MySQLDatabase.java    From modernmt with Apache License 2.0 6 votes vote down vote up
public MySQLDatabase(String host, int port, String name, String user, String password) {
    super(null);
    this.name = name;

    String params = "useUnicode=true"
            + "&useJDBCCompliantTimezoneShift=true"
            + "&useLegacyDatetimeCode=false"
            + "&serverTimezone=UTC";

    MysqlDataSource mysqlDS = new MysqlDataSource();
    mysqlDS.setURL("jdbc:mysql://" + host + ":" + port + "/" + name + "?" + params);
    mysqlDS.setDatabaseName(name);
    mysqlDS.setUser(user);
    mysqlDS.setPassword(password);
    this.dataSource = mysqlDS;
}
 
Example 3
Source File: CatalogMultitenancyTest.java    From high-performance-java-persistence with Apache License 2.0 6 votes vote down vote up
private void addTenantConnectionProvider(String tenantId) {
    DataSourceProvider dataSourceProvider = database().dataSourceProvider();

    Properties properties = properties();

    MysqlDataSource tenantDataSource = new MysqlDataSource();
    tenantDataSource.setDatabaseName(tenantId);
    tenantDataSource.setUser(dataSourceProvider.username());
    tenantDataSource.setPassword(dataSourceProvider.password());

    properties.put(
            Environment.DATASOURCE,
            dataSourceProxyType().dataSource(tenantDataSource)
    );

    addTenantConnectionProvider(tenantId, tenantDataSource, properties);
}
 
Example 4
Source File: MySqlDataSourceFactory.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
@Override
protected DataSource createDataSource() {
    final MySQLContainer container = mysqlContainer();
    final MysqlDataSource dataSource = new MysqlDataSource();
    dataSource.setUrl(container.getJdbcUrl());
    dataSource.setUser(container.getUsername());
    dataSource.setPassword(container.getPassword());
    dataSource.setDatabaseName(container.getDatabaseName());
    return dataSource;
}