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

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

Introduction

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

Prototype

public void setPassword(@Nullable String password) 

Source Link

Document

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

Usage

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

/**
 * This creates a generic datasource for the web application.
 * //w ww.  j a  v  a  2 s . c o 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 {// w w  w  .  ja v a 2  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;
}