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

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

Introduction

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

Prototype

public void setDriverClass(Class<? extends Driver> driverClass) 

Source Link

Document

Specify the JDBC Driver implementation class to use.

Usage

From source file:ua.biglib.salivon.BookConfig.java

@Bean
public DataSource dataSource() {
    SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
    dataSource.setDriverClass(Driver.class);
    dataSource.setUrl("jdbc:mysql://localhost:3306/biglib");
    dataSource.setUsername("root");
    dataSource.setPassword("");
    return dataSource;
}

From source file:org.dawnsci.marketplace.config.DatabaseConfiguration.java

private SimpleDriverDataSource createDataSource() {
    SimpleDriverDataSource simpleDriverDataSource = new SimpleDriverDataSource();
    simpleDriverDataSource.setDriverClass(org.hsqldb.jdbcDriver.class);
    simpleDriverDataSource.setUrl(environment.getProperty("marketplace.system-db"));
    simpleDriverDataSource.setUsername("");
    simpleDriverDataSource.setPassword("");
    return simpleDriverDataSource;
}

From source file:com.emo.ananas.configs.DataSourceConfig.java

public DataSource build() {
    if (user != null && driverClass != null) {
        final SimpleDriverDataSource ds = new SimpleDriverDataSource();
        ds.setUrl(url);/*from w  ww  . j  a  v a  2  s  .  c om*/
        ds.setDriverClass(driverClass);
        ds.setUsername(user);
        ds.setPassword(password);

        return ds;
    } else if (user != null && driverClass == null) {
        return new DriverManagerDataSource(url, user, password);
    } else if (user == null & driverClass != null) {
        final SimpleDriverDataSource ds = new SimpleDriverDataSource();
        ds.setUrl(url);
        ds.setDriverClass(driverClass);

        return ds;
    } else {
        return new DriverManagerDataSource(url);
    }
}

From source file:com.springsource.html5expense.config.LocalDataSourceConfig.java

@Bean
@Override/*from  ww w.j a  v a2s  .c om*/
public DataSource dataSource() throws Exception {
    SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
    dataSource.setUrl(String.format("jdbc:postgresql://%s:%s/%s", "127.0.0.1", 5432, "expenses"));
    dataSource.setDriverClass(Driver.class);
    dataSource.setUsername("expenses");
    dataSource.setPassword("expenses");
    return dataSource;
}

From source file:com.github.djabry.platform.service.data.config.MySQLDataConfig.java

@Override
public DataSource dataSource() {

    SimpleDriverDataSource d = new SimpleDriverDataSource();

    d.setUrl("jdbc:mysql://example-host.com:3306/example_db");
    d.setUsername("myusername");
    d.setPassword("mypassword");
    d.setDriverClass(com.mysql.jdbc.Driver.class);

    return d;/*  ww  w .  j  a v  a2s . c  om*/

}

From source file:com.springsource.html5expense.config.ComponentConfig.java

@Bean
public DataSource dataSource() {
    SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
    dataSource.setUrl(String.format("jdbc:postgresql://%s:%s/%s", "192.168.6.30", 5432, "postgres"));
    dataSource.setDriverClass(org.postgresql.Driver.class);
    dataSource.setUsername("postgres");
    dataSource.setPassword("pramati123");
    return dataSource;
}

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:org.springsource.html5expenses.config.ServicesConfiguration.java

@Bean
@SuppressWarnings("unchecked")
public DataSource dataSource() throws Exception {
    SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
    dataSource.setPassword(environment.getProperty("dataSource.password"));
    dataSource.setUrl(environment.getProperty("dataSource.url"));
    dataSource.setUsername(environment.getProperty("dataSource.user"));
    dataSource.setDriverClass((Class<Driver>) Class.forName(environment.getProperty("dataSource.driverClass")));
    return dataSource;
}

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

/**
 * This creates a generic datasource for the web application.
 * /*from w ww.j  av 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 {//from ww w.j av  a2  s.co 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;
}