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

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

Introduction

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

Prototype

public void setUsername(@Nullable String username) 

Source Link

Document

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

Usage

From source file:com.pactera.edg.am.metamanager.extractor.adapter.extract.db.impl.TeradataExtractServiceImpl.java

public static void main(String[] args) throws SQLException, FileNotFoundException, IOException {
    IDBExtractService extractor = new TeradataExtractServiceImpl();
    org.springframework.jdbc.datasource.DriverManagerDataSource dSource = new org.springframework.jdbc.datasource.DriverManagerDataSource();
    // dSource.setDriverClassName("com.ncr.teradata.TeraDriver");
    // dSource.setUrl("jdbc:teradata://172.19.0.158/CLIENT_CHARSET=cp936,TMODE=TERA,CHARSET=ASCII,DATABASE=MM");
    // dSource.setUsername("mmuser");
    // dSource.setPassword("mmuser");
    // extractor.setSchemas("MM");
    // File file = new File("d:\\catalog");
    ///*from   ww  w.  j  av  a  2 s . c o  m*/
    // ObjectOutput output = new ObjectOutputStream(new
    // FileOutputStream(file));
    //
    // // ?
    //
    // output.writeObject(c);
    //
    // output.close();
    //
    // System.out.println("?" + file.getAbsolutePath());
    Log4jInit.init();
    // extractor = new TeradataExtractServiceImpl();
    dSource.setDriverClassName("com.ncr.teradata.TeraDriver");
    dSource.setUrl("jdbc:teradata://172.16.171.24/CLIENT_CHARSET=cp936,TMODE=TERA,CHARSET=ASCII,DATABASE=MM");
    // dSource.setUrl("jdbc:teradata://172.19.166.203/CLIENT_CHARSET=cp936,TMODE=TERA,CHARSET=ASCII,DATABASE=MM");
    dSource.setUsername("mmuser");
    dSource.setPassword("mmuser");
    ((DBExtractBaseServiceImpl) extractor).setSchemas("edwbview");
    // ((DBExtractBaseServiceImpl) extractor).setSchemas("mm2");
    // ((DBExtractBaseServiceImpl) extractor).setSchemas("MM");
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dSource);

    ((DBExtractBaseServiceImpl) extractor).setJdbcTemplate(jdbcTemplate);
    extractor.getCatalog();

}

From source file:com.fmguler.ven.LiquibaseUtil.java

/**
 * @return DataSource for the test database
 *///  w  w  w  .ja  v  a2s .c om
public static DataSource getDataSource() {
    DriverManagerDataSource ds = new DriverManagerDataSource();
    ds.setDriverClassName("org.postgresql.Driver");
    ds.setUsername("postgres");
    ds.setPassword("qwerty");
    ds.setUrl("jdbc:postgresql://127.0.0.1:5432/ven-test");
    return ds;
}

From source file:com.google.api.ads.adwords.awalerting.util.JdbcUtil.java

/**
 * Create a JdbcTemplate according to the parameters.
 *
 * @param dbConfig the Json configuration for database connection
 * @param driverKey the key for JDBC driver class name
 * @param urlKey the key for JDBC url/*from  w w w. j a  v  a2s  . c  o m*/
 * @param usernameKey the key for JDBC username
 * @param passwordKey the key JDBC password
 * @return a JdbcTemplate with the given parameters
 */
public static JdbcTemplate createJdbcTemplate(JsonObject dbConfig, String driverKey, String urlKey,
        String usernameKey, String passwordKey) {
    // Read the config values.
    String driver = DEFAULT_DB_DRIVER;
    if (dbConfig.has(driverKey)) {
        driver = dbConfig.get(driverKey).getAsString();
    }

    Preconditions.checkArgument(dbConfig.has(urlKey), "Missing compulsory property: %s", urlKey);
    String url = dbConfig.get(urlKey).getAsString();

    String username = null;
    if (dbConfig.has(usernameKey)) {
        username = dbConfig.get(usernameKey).getAsString();
    }

    String password = null;
    if (dbConfig.has(passwordKey)) {
        password = dbConfig.get(passwordKey).getAsString();
    }

    // Create the data source.
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(driver);
    dataSource.setUrl(url);
    dataSource.setUsername(username);
    dataSource.setPassword(password);

    // Create the JdbcTemplate with the data srouce.
    return new JdbcTemplate(dataSource);
}

From source file:at.christophwurst.orm.test.IntegrationTest.java

@BeforeClass
public static void setUpClass() {
    Operation operation = DbOperations.PREPARE_DB;
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName("org.apache.derby.jdbc.ClientDriver");
    dataSource.setUrl("jdbc:derby://localhost/WorkLogDb;create=true");
    dataSource.setUsername("user");
    dataSource.setPassword("test");
    dbSetup = new DbSetup(new DataSourceDestination(dataSource), operation);
}

From source file:org.tonguetied.test.common.PersistenceTestBase.java

/**
 * Create and initialize the database connection.
 * /*from   www  . ja va2s.  com*/
 * @param properties
 */
protected static void initializeDataSource(Properties properties) {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setUrl(properties.getProperty(KEY_JDBC_URL));
    dataSource.setDriverClassName(properties.getProperty(KEY_JDBC_DRIVER));
    dataSource.setUsername(properties.getProperty(KEY_JDBC_USER_NAME));
    dataSource.setPassword(properties.getProperty(KEY_JDBC_PASSWORD));
    //        final DatasourceConnectionProvider provider = new DatasourceConnectionProvider();
    //        provider.configure(properties);
    template = new SimpleJdbcTemplate(dataSource);
}

From source file:com.rplt.studioMusik.model.DatabaseConnection.java

public static DataSource getmDataSource() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    //        dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");  
    //        dataSource.setUrl("jdbc:oracle:thin:@172.23.9.185:1521:orcl");
    //        dataSource.setUsername("mhs125314109");
    //        dataSource.setPassword("mhs125314109");

    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    dataSource.setUrl("jdbc:mysql://localhost:3306/studiomusik");
    dataSource.setUsername("mhs125314109");
    dataSource.setPassword("mhs125314109");

    return dataSource;
}

From source file:net.firejack.platform.core.utils.db.DBUtils.java

/**
 * @param driverClassName driver classname
 * @param url jdbc url/* w  w  w  .j a v  a  2s .  c  o m*/
 * @param user db user
 * @param password db user password
 * @return returns populated data-source
 */
public static DataSource populateDataSource(String driverClassName, String url, String user, String password) {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(driverClassName);
    dataSource.setUrl(url);
    dataSource.setUsername(user);
    dataSource.setPassword(password);
    return dataSource;
}

From source file:org.owasp.proxy.Main.java

private static DataSource createDataSource(Configuration config) throws SQLException {
    if (config.jdbcDriver == null)
        return null;
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(config.jdbcDriver);
    dataSource.setUrl(config.jdbcUrl);/*from www. j a  v a 2s. c  o  m*/
    dataSource.setUsername(config.jdbcUser);
    dataSource.setPassword(config.jdbcPassword);
    return dataSource;
}

From source file:com.google.enterprise.connector.sharepoint.TestConfiguration.java

/**
 * gets a sample data source for user data store
 * //from   w  ww .  j av  a 2s  .  c om
 * @return
 */
public static DataSource getUserDataSource() {
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(TestConfiguration.driverClass);
    dataSource.setUrl(TestConfiguration.dbUrl);
    dataSource.setUsername(TestConfiguration.dbUsername);
    dataSource.setPassword(TestConfiguration.dbPassword);
    return dataSource;
}

From source file:br.com.alura.casadocodigo.conf.JPAConfiguration.java

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {

    LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();

    JpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    factoryBean.setJpaVendorAdapter(adapter);

    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setUsername("root");
    dataSource.setPassword("");
    dataSource.setUrl("jdbc:mysql://localhost:3306/casadocodigo");
    dataSource.setDriverClassName("com.mysql.jdbc.Driver");
    factoryBean.setDataSource(dataSource);

    Properties properties = new Properties();
    properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
    properties.setProperty("hibernate.show_sql", "true");
    properties.setProperty("hibernate.hbm2ddl.auto", "update");
    factoryBean.setJpaProperties(properties);

    factoryBean.setPackagesToScan("br.com.alura.casadocodigo.models");

    return factoryBean;
}