Example usage for org.springframework.jdbc.datasource DriverManagerDataSource DriverManagerDataSource

List of usage examples for org.springframework.jdbc.datasource DriverManagerDataSource DriverManagerDataSource

Introduction

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

Prototype

public DriverManagerDataSource(String url, String username, String password) 

Source Link

Document

Create a new DriverManagerDataSource with the given standard DriverManager parameters.

Usage

From source file:org.string_db.jdbc.DriverDataSourceConfig.java

@Override
@Bean //need to repeat the annotation
public DataSource dataSource() {
    if (!env.containsProperty("jdbc.url")) {
        throw new ExceptionInInitializerError("missing property 'jdbc.url' " + env);
    }//  w w w. ja  v a2s .  co m
    return new DriverManagerDataSource(env.getProperty("jdbc.url"), env.getProperty("jdbc.username"),
            env.getProperty("jdbc.password"));
}

From source file:com.recomdata.grails.rositaui.utils.SignalService.java

@Override
public void afterPropertiesSet() throws Exception {
    ds = new DriverManagerDataSource(dbUrl, dbUsername, dbPassword);
    ps = ds.getConnection().prepareStatement(
            "INSERT INTO cz.cz_workflow_signal(job_id, workflow_step, date, pending, success, message) VALUES (?, ?, ?, ?, ?, ?);");
    consolePs = ds.getConnection()//from w w w  . j  a  v  a 2s.c  om
            .prepareStatement("INSERT INTO cz.cz_console_output(step_id, date, message) VALUES (?,?,?)");
    me = this;
}

From source file:nz.geek.caffe.spring.ase.AseExceptionMappingTest.java

/**
 * Setup./*from   w w w .  jav  a 2s.  c o  m*/
 */
@Before
public void setup() {
    this.datasource = new DriverManagerDataSource(
            System.getProperty("jdbcUrl", "jdbc:sybase:Tds:localhost:5000/test"),
            System.getProperty("jdbcUser", "spring"), System.getProperty("jdbcPassword", "spring"));

    this.jdbcTemplate = new JdbcTemplate(this.datasource);

    dropTables();

    this.jdbcTemplate.execute("create table TEST_PARENT(ID_ int, STR_ varchar(10), primary key (ID_))");
    this.jdbcTemplate.execute(
            "create table TEST_CHILD(ID_ int, STR_ varchar(10), PARENT_ int not null, primary key (ID_))");

    this.jdbcTemplate.execute(
            "alter table TEST_CHILD add constraint FK_PARENT_CHILD foreign key (PARENT_) references TEST_PARENT(ID_)");
}

From source file:com.osrdata.etltoolbox.fileloader.FileLoader.java

/**
 * Initializes this class, parsing command line arguments and specification file.
 *
 * @throws ParseException/* w  w w  .  j  av  a 2  s . c  o m*/
 * @throws IOException
 */
public void init() throws ParseException, IOException {
    if (commandLine.hasOption("trace")) {
        trace = Long.parseLong(commandLine.getOptionValue("trace"));
    }
    replaceExisting = commandLine.hasOption("replace");

    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> root = mapper.readValue(new File(commandLine.getOptionValue("spec")), Map.class);

    String auditUrl = (String) root.get("auditUrl");
    String auditUser = (String) root.get("auditUser");
    String auditPassword = (String) root.get("auditPassword");
    DataSource auditDs = new DriverManagerDataSource(auditUrl, auditUser, auditPassword);

    String targetUrl = (String) root.get("targetUrl");
    String targetUser = (String) root.get("targetUser");
    String targetPassword = (String) root.get("targetPassword");
    DataSource targetDs = new DriverManagerDataSource(targetUrl, targetUser, targetPassword);

    int batchThreshold = (Integer) root.get("batchThreshold");
    List<Object> mappings = (List<Object>) root.get("mappings");
    for (Object mapping : mappings) {
        specs.add(new FileSpecification((Map<String, Object>) mapping, auditDs, targetDs, batchThreshold,
                replaceExisting, trace));
    }

    // Load database dribers from lib folder.
    File libDirectory = new File("lib");
    if (libDirectory.isDirectory()) {
        File[] jarFiles = libDirectory.listFiles();

        for (File jarFile : jarFiles) {
            if (jarFile.getName().endsWith(".jar")) {
                ClassLoaderUtil.addFileToClassPath(jarFile, this.getClass().getClassLoader());
                log.info("Added " + jarFile.getName() + " to classpath");
            }
        }
    }
}

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);/*w  w w.  j a  va  2  s.  c o m*/
        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:dk.nsi.minlog.export.config.DatabaseConfig.java

@Bean
public DataSource dataSource() {
    final DriverManagerDataSource dataSource = new DriverManagerDataSource(url, username, password);
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    return dataSource;
}

From source file:info.naiv.lab.java.tool.sqlite.exporter.component.Source.java

/**
 *
 * @param props/*from w  ww. j a  v a2  s .c o  m*/
 * @param dataAccess
 */
public Source(Properties props, DataAccess dataAccess) {

    String url = props.getProperty("datasource.url");
    if (isBlank(url)) {
        throw new IllegalArgumentException("DataSource url is blank");
    }

    String userid = props.getProperty("datasource.username");
    String password = props.getProperty("datasource.password");
    String tables = props.getProperty("datasource.exclude.tables");
    this.excludeTables = commaDelimitedListToSet(tables);
    this.props = props;
    this.schema = props.getProperty("datasource.schema");
    if ("@null".equals(this.schema)) {
        this.schema = null;
    }
    this.classTemplate = new ClassPathResource("sqliteSchema.sql");
    this.dataAccess = dataAccess;
    this.jdbcTemplate = new JdbcTemplate(new DriverManagerDataSource(url, userid, password));
}

From source file:dk.nsi.minlog.test.TestDBConfig.java

@Bean
public DataSource dataSource() {
    final DriverManagerDataSource dataSource = new DriverManagerDataSource("jdbc:mysql:mxj:///minlog"
            + "?server.basedir=" + getDatabaseDir() + "&createDatabaseIfNotExist=true", "root", "");
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    return dataSource;
}

From source file:org.awesomeagile.dao.testing.TestDatabase.java

public DriverManagerDataSource getDataSource() {
    return new DriverManagerDataSource(/* url */ getUrl(), /* username */ "postgres", /* password */ "");
}

From source file:org.awesomeagile.dao.testing.TestDatabase.java

public DataSource getDataSource(String database) {
    return new DriverManagerDataSource(/* url */ getUrl(database), /* username */ "postgres",
            /* password */ "");
}