Java Code Examples for com.mysql.jdbc.jdbc2.optional.MysqlDataSource#setURL()

The following examples show how to use com.mysql.jdbc.jdbc2.optional.MysqlDataSource#setURL() . 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: SessionPropertiesDaoProvider.java    From presto with Apache License 2.0 6 votes vote down vote up
@Inject
public SessionPropertiesDaoProvider(DbSessionPropertyManagerConfig config)
{
    requireNonNull(config, "config is null");
    String url = requireNonNull(config.getConfigDbUrl(), "db url is null");

    MysqlDataSource dataSource = new MysqlDataSource();
    dataSource.setURL(url);

    Optional<String> username = Optional.ofNullable(config.getUsername());
    username.ifPresent(dataSource::setUser);

    Optional<String> password = Optional.ofNullable(config.getPassword());
    password.ifPresent(dataSource::setPassword);

    this.dao = Jdbi.create(dataSource)
            .installPlugin(new SqlObjectPlugin())
            .onDemand(SessionPropertiesDao.class);
}
 
Example 2
Source File: TestDbSessionPropertyManagerIntegration.java    From presto with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
public void setupTest()
{
    queryRunner.getCoordinator().getSessionPropertyDefaults()
            .setConfigurationManager("db-test", ImmutableMap.<String, String>builder()
                    .put("session-property-manager.db.url", mysqlContainer.getJdbcUrl())
                    .put("session-property-manager.db.username", mysqlContainer.getUsername())
                    .put("session-property-manager.db.password", mysqlContainer.getPassword())
                    .build());

    MysqlDataSource dataSource = new MysqlDataSource();
    dataSource.setURL(mysqlContainer.getJdbcUrl());
    dataSource.setUser(mysqlContainer.getUsername());
    dataSource.setPassword(mysqlContainer.getPassword());
    dao = Jdbi.create(dataSource)
            .installPlugin(new SqlObjectPlugin())
            .onDemand(SessionPropertiesDao.class);
}
 
Example 3
Source File: DataIntegrityTestTool.java    From adt with Apache License 2.0 6 votes vote down vote up
public DataIntegrityTestTool(Properties prop) throws Exception{
    
    this.setName("data-integrity-test-thread");
    
    srcDs = new MysqlDataSource();
    srcDs.setURL(prop.getProperty(DMLQueryTool.PROP_MSR_SRC_URL));
    srcDs.setUser(prop.getProperty(DMLQueryTool.PROP_MSR_SRC_USERNAME));
    srcDs.setPassword(prop.getProperty(DMLQueryTool.PROP_MSR_SRC_PASSWROD));
    
    destCount = Integer.parseInt(prop.getProperty(DMLQueryTool.PROP_MSR_DEST_COUNT));
    destDs = new MysqlDataSource[destCount];
    for(int i=0; i<destCount; i++){
        destDs[i] = new MysqlDataSource();
        destDs[i].setURL(prop.getProperty(String.format(DMLQueryTool.PROP_MSR_DEST_URL, i)));
        destDs[i].setUser(prop.getProperty(String.format(DMLQueryTool.PROP_MSR_DEST_USERNAME, i)));
        destDs[i].setPassword(prop.getProperty(String.format(DMLQueryTool.PROP_MSR_DEST_PASSWORD, i)));
    }
}
 
Example 4
Source File: MySqlTestSettings.java    From dashbuilder with Apache License 2.0 6 votes vote down vote up
@Override
public SQLDataSourceLocator getDataSourceLocator() {
    return new SQLDataSourceLocator() {
        public DataSource lookup(SQLDataSetDef def) throws Exception {
            String url = connectionSettings.getProperty("url");
            String user = connectionSettings.getProperty("user");
            String password = connectionSettings.getProperty("password");

            MysqlDataSource ds = new MysqlDataSource();
            ds.setURL(url);
            if (!StringUtils.isBlank(user)) {
                ds.setUser(user);
            }
            if (!StringUtils.isBlank(password)) {
                ds.setPassword(password);
            }
            return ds;
        }
    };
}
 
Example 5
Source File: BaseVersionedMySQLSupport.java    From boon with Apache License 2.0 6 votes vote down vote up
/**
 * Connects to the DB and tracks if successful so upstream stuff can try to reconnect.
 */
protected void connect() {

    try {
        MysqlDataSource dataSource = new MysqlDataSource();
        dataSource.setURL(url);
        dataSource.setPassword(password);
        dataSource.setUser(userName);
        connection = dataSource.getConnection();
        connection.setAutoCommit(true);
        closed = false;
        totalConnectionOpen++;
    } catch (SQLException sqlException) {
        this.closed = true;
        connection = null;

        handle("Unable to connect", sqlException);

    }


}
 
Example 6
Source File: BaseMySQLSupport.java    From boon with Apache License 2.0 6 votes vote down vote up
protected void connect() {

        try {
            MysqlDataSource dataSource = new MysqlDataSource();
            dataSource.setURL(url);
            dataSource.setPassword(password);
            dataSource.setUser(userName);
            connection = dataSource.getConnection();
            connection.setAutoCommit(true);
            closed = false;
            totalConnectionOpen++;
        } catch (SQLException sqlException) {
            this.closed = true;
            connection = null;

            handle("Unable to connect", sqlException);

        }


    }
 
Example 7
Source File: MysqlDaoProvider.java    From presto with Apache License 2.0 5 votes vote down vote up
@Inject
public MysqlDaoProvider(DbResourceGroupConfig config)
{
    requireNonNull(config, "DbResourceGroupConfig is null");
    MysqlDataSource dataSource = new MysqlDataSource();
    dataSource.setURL(requireNonNull(config.getConfigDbUrl(), "resource-groups.config-db-url is null"));
    this.dao = Jdbi.create(dataSource)
            .installPlugin(new SqlObjectPlugin())
            .onDemand(ResourceGroupsDao.class);
}
 
Example 8
Source File: HandlerTest.java    From adt with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception{
    initializeTestEnv();
    
    final int sleepCount = 30;
    
    LOGGER.debug("sleep " + sleepCount + "sec for generating enough test data");
    for(int i=1; i<=sleepCount; i++){
        LOGGER.debug(i + "/" + sleepCount);
        Thread.sleep(1000);
    }
    
    dataSource = new MysqlDataSource();
    dataSource.setURL(DB_URL);
    dataSource.setUser(DB_USER);
    dataSource.setPassword(DB_PW);
    
    for(int i=0; i<SHARD_COUNT; i++){
        
        Connection connDest = DriverManager.getConnection(DB_DEST_URL_LIST_WITHOUT_SCHEMA[i], DB_USER, DB_PW);
        try{
            Statement stmt = connDest.createStatement();
            stmt.execute("DROP DATABASE IF EXISTS " + DB_DEST_SCHEMA_LIST[i]);
            stmt.execute("CREATE DATABASE " + DB_DEST_SCHEMA_LIST[i]);
            stmt.execute(String.format(TestUtil.getResourceAsString("sql/create_table_adt_test_1.sql"), DB_DEST_SCHEMA_LIST[i]));
            stmt.execute(String.format(TestUtil.getResourceAsString("sql/create_table_adt_test_2.sql"), DB_DEST_SCHEMA_LIST[i]));
            stmt.execute(String.format(TestUtil.getResourceAsString("sql/create_table_adt_test_3.sql"), DB_DEST_SCHEMA_LIST[i]));
        }finally{
            connDest.close();
        }
        
    }
        
}
 
Example 9
Source File: Util.java    From DKO with GNU Lesser General Public License v2.1 5 votes vote down vote up
public synchronized static DataSource getDS() {
	if (ds==null) {
		MysqlDataSource tmpDS = new MysqlDataSource();
		tmpDS.setURL("jdbc:mysql://localhost/sakila");
		tmpDS.setUser("root");
		tmpDS.setPassword("");
		ds = tmpDS;
	}
	return ds;
}
 
Example 10
Source File: DbUtilsDemo.java    From JavaTutorial with Apache License 2.0 3 votes vote down vote up
/**
 * 创建JDBC连接池。
 * 
 * @param pros 数据库连接信息,里面包含4个键值对。
 * <pre>
 * jdbcDriver => JDBC驱动类名称
 * url => 数据库JDBC连接地址
 * user => 连接数据库的用户名
 * password => 连接数据库的密码
 * <pre>
 * @return 连接池对象
 */
private DataSource createDataSource(Properties pros) {
    MysqlDataSource ds = new MysqlDataSource();
    ds.setURL(pros.getProperty("url"));
    ds.setUser(pros.getProperty("user"));
    ds.setPassword(pros.getProperty("password"));
    
    return ds;
}