Example usage for org.springframework.jdbc.datasource SimpleDriverDataSource setUrl

List of usage examples for org.springframework.jdbc.datasource SimpleDriverDataSource setUrl

Introduction

In this page you can find the example usage for org.springframework.jdbc.datasource SimpleDriverDataSource setUrl.

Prototype

public void setUrl(@Nullable String url) 

Source Link

Document

Set the JDBC URL to use for connecting through the Driver.

Usage

From source file:org.springsource.greenbeans.examples.edawithspring.etailer.backoffice.PartnerNotificationConfiguration.java

@Bean
public DataSource dataSource() {
    SimpleDriverDataSource simpleDriverDataSource = new SimpleDriverDataSource();
    simpleDriverDataSource.setPassword(this.dsPassword);
    simpleDriverDataSource.setUsername(this.dsUser);
    simpleDriverDataSource.setDriverClass(org.h2.Driver.class);
    simpleDriverDataSource.setUrl(this.dsUrl);
    return simpleDriverDataSource;
}

From source file:com.webapp.config.DataBaseConfig.java

/**
 * This creates a generic datasource for the web application.
 * //from   w ww . j  a  v  a2  s. co  m
 * <p>It uses system properties to determine the configuration.</p>
 * 
 * @return A datasource 
 */
@Bean
public DataSource dataSource() {
    LOG.info("Creating a datasource..");
    SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
    try {
        LOG.info("Classname: " + env.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER));
        @SuppressWarnings("unchecked")
        Class<? extends Driver> driverClass = (Class<? extends Driver>) Class
                .forName(env.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER));
        dataSource.setDriverClass(driverClass);

        LOG.info("URL: " + env.getRequiredProperty(PROPERTY_NAME_DATABASE_URL));
        dataSource.setUrl(env.getRequiredProperty(PROPERTY_NAME_DATABASE_URL));

        LOG.info("User: " + env.getRequiredProperty(PROPERTY_NAME_DATABASE_USERNAME));
        dataSource.setUsername(env.getRequiredProperty(PROPERTY_NAME_DATABASE_USERNAME));

        dataSource.setPassword(env.getRequiredProperty(PROPERTY_NAME_DATABASE_PASSWORD));
        LOG.info("Datasource created successfully.");
    } catch (ClassNotFoundException | IllegalStateException e) {
        LOG.fatal("Could not create driver class '" + env.getRequiredProperty(PROPERTY_NAME_DATABASE_DRIVER)
                + "'", e);
    }

    return dataSource;
}

From source file:org.netxilia.api.impl.storage.DataSourceConfigurationServiceImpl.java

@SuppressWarnings("unchecked")
public DataSource buildSimpleDataSource(DataSourceConfiguration cfg) {
    SimpleDriverDataSource dataSource = new SimpleDriverDataSource();

    Class<? extends Driver> driverClass;
    try {/*ww w  .  j a v  a2 s.  c  o m*/
        driverClass = (Class<? extends Driver>) Class.forName(cfg.getDriverClassName());
    } catch (ClassNotFoundException e) {
        throw new NetxiliaResourceException("Cannot find class driver:" + cfg.getDriverClassName());
    }
    dataSource.setDriverClass(driverClass);
    dataSource.setUrl(cfg.getUrl().replace(NETXILIA_HOME_VAR, path));
    dataSource.setUsername(cfg.getUsername());
    dataSource.setPassword(cfg.getPassword());
    return dataSource;
}

From source file:org.openflamingo.engine.hive.HiveServiceImpl.java

@Override
public List<String> getDatabases(HiveServer hiveServer) {
    try {//from  w ww .  j ava  2  s .  c  o  m
        SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
        dataSource.setDriverClass(org.apache.hive.jdbc.HiveDriver.class);
        dataSource.setUrl(hiveServer.getJdbcUrl());

        final List<String> list = new ArrayList<String>();
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        jdbcTemplate.query("show databases", new RowCallbackHandler() {
            @Override
            public void processRow(ResultSet resultSet) throws SQLException {
                list.add(resultSet.getString("database_name"));
            }
        });
        return list;
    } catch (Exception ex) {
        throw new ServiceException(message("S_HIVE", "CANNOT_GET_HIVE_DBS"), ex);
    }
}