List of usage examples for org.springframework.jdbc.datasource DriverManagerDataSource setUsername
public void setUsername(@Nullable String username)
From source file:py.una.pol.karaku.test.configuration.TransactionTestConfiguration.java
/** * Crea un datasource para una base de datos embebida. * //from w w w.j ava2 s . c o m * @return dataSource creada o null si no se necesita un datasource * @throws IOException * si no se puede crear la base de datos */ @Bean public DataSource dataSource() throws IOException { DataSource ds; if (properties.getBoolean(USE_EMBEDDED, true)) { EmbeddedDatabaseBuilder edb = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2); ds = edb.build(); } else { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setUrl(properties.get("test.hiberante.database")); dataSource.setUsername(properties.get("test.hibernate.user")); dataSource.setPassword(properties.get("test.hibernate.pass")); ds = dataSource; } return ds; }
From source file:com.wms.multitenant.tenant.provider.MultiTenantConnectionProviderImpl.java
private DataSource constructDataSource(String dbName) { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(/* ww w .ja v a 2 s.com*/ springEnvironment.getProperty("tenant.datasource.classname", "com.mysql.jdbc.Driver")); dataSource.setUrl(springEnvironment.getProperty("tenant.datasource.url", "jdbc:mysql://localhost:3306/") + dbName + "?createDatabaseIfNotExist=true"); dataSource.setUsername(springEnvironment.getProperty("tenant.datasource.user", "root")); dataSource.setPassword(springEnvironment.getProperty("tenant.datasource.password", "root")); // ResourceDatabasePopulator rdp = new ResourceDatabasePopulator(); // rdp.populate(dataSource.getConnection()); try { dataSource.getConnection().createStatement().execute("CREATE DATABASE IF NOT EXISTS " + dbName); dataSource.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS `product` (\n" + " `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n" + " `name` varchar(128) NOT NULL,\n" + " `product_id` varchar(128) DEFAULT NULL,\n" + " `price` double DEFAULT NULL,\n" + " `description` varchar(256) DEFAULT NULL,\n" + " `created` timestamp NULL DEFAULT NULL,\n" + " `updated` timestamp NULL DEFAULT NULL,\n" + " `deleted` timestamp NULL DEFAULT NULL,\n" + " PRIMARY KEY (`id`),\n" + " UNIQUE KEY `name` (`name`)\n" + ") ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;"); } catch (Exception ex) { System.out.println(ex); } return dataSource; }
From source file:com.wms.multitenant.config.MasterDatabaseConfig.java
@Bean public DataSource dataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(/*ww w . j a v a2s . co m*/ springEnvironment.getProperty("master.datasource.classname", "com.mysql.jdbc.Driver")); dataSource .setUrl(springEnvironment.getProperty("master.datasource.url", "jdbc:mysql://localhost:3306/master") + "?createDatabaseIfNotExist=true"); dataSource.setUsername(springEnvironment.getProperty("master.datasource.user", "root")); dataSource.setPassword(springEnvironment.getProperty("master.datasource.password", "root")); return dataSource; }
From source file:com.iucosoft.eavertizare.dao.impl.ClientsDaoImpl.java
@Override public List<Client> findAllClientsForFirmaRemote(Firma firma) { DriverManagerDataSource dataSourceClient = new DriverManagerDataSource(); dataSourceClient.setDriverClassName(firma.getConfiguratii().getDriver()); dataSourceClient.setUrl(firma.getConfiguratii().getUrlDb()); dataSourceClient.setUsername(firma.getConfiguratii().getUsername()); dataSourceClient.setPassword(firma.getConfiguratii().getPassword()); String query = "select * from " + firma.getConfiguratii().getTabelaClienti(); List<Client> clientsList = new ArrayList<>(); try (Connection con = dataSourceClient.getConnection(); PreparedStatement ps = con.prepareStatement(query); ResultSet rs = ps.executeQuery();) { while (rs.next()) { Client client = new Client(); client.setId(rs.getInt(1));//from w w w . j a va 2 s . co m client.setNume(rs.getString(2)); client.setPrenume(rs.getString(3)); client.setNrTelefon(rs.getInt(4)); client.setEmail(rs.getString(5)); client.setDateExpirare(rs.getTimestamp(6)); clientsList.add(client); } } catch (SQLException e) { e.printStackTrace(); } return clientsList; }
From source file:com.dhenton9000.birt.configs.DatabaseConfig.java
@Bean public DataSource dataSource() { URI dbUrl = null;/*from w ww . j av a2s . c om*/ String dbString = env.getProperty("DATABASE_URL"); log.debug("database string " + dbString); try { dbUrl = new URI(dbString); } catch (URISyntaxException ex) { throw new RuntimeException(ex.getMessage()); } DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("org.postgresql.Driver"); String url = "jdbc:postgresql://" + dbUrl.getHost() + ":" + dbUrl.getPort() + dbUrl.getPath(); // log.debug("url "+url); dataSource.setUrl(url); // log.debug("info user "+dbUrl.getUserInfo()); dataSource.setUsername(dbUrl.getUserInfo().split(":")[0]); dataSource.setPassword(dbUrl.getUserInfo().split(":")[1]); return dataSource; }
From source file:com.mycompany.projetsportmanager.spring.configuration.H2ProfileConfiguration.java
/** * Builds a JNDI datasource./*w ww .j a v a2s. c o m*/ * @return the datasource. */ @Bean public DataSource dataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(Driver.class.getName()); // String h2Url = MessageFormat.format("jdbc:h2:file:{0}ProjetSportManager;MODE=Oracle", System.getProperty("java.io.tmpdir")); String h2Url = "jdbc:h2:file:c:\\temp\\ProjetSportManager;MODE=Oracle"; logger.info("Using H2 with URL : {}", h2Url); dataSource.setUrl(h2Url); dataSource.setUsername("sa"); dataSource.setPassword(""); return dataSource; }
From source file:com.jmstoolkit.pipeline.plugin.XMLValueTransform.java
/** * Constructor for creating a useful <code>XMLValueTransform</code>. * * @param pluginName The human readable name for the Transform. * @param inConfig The SQL query for looking up the value. * @param inputName The JNDI name of the JMS Destination to subscribe to. * @param outputName The JNDI name of the JMS Destination to publish to. * @param replyToName The JNDI name of the JMS Destination for reply/status. * @param connectionFactory A JMS ConnectionFactory implementation. * @param inJndiTemplate The JndiTemplate. *///from w w w . j a v a 2s . c om public XMLValueTransform(final String pluginName, final String inConfig, final String inputName, final String outputName, final String replyToName, final ConnectionFactory connectionFactory, final JndiTemplate inJndiTemplate) { super(); this.jndiTemplate = inJndiTemplate; this.name = pluginName; this.inName = inputName; this.outName = outputName; this.replyToName = replyToName; try { // Setup the JMS Destinations setInput((Destination) getJndiTemplate().lookup(inputName, Destination.class)); setOutput((Destination) getJndiTemplate().lookup(outputName, Destination.class)); setReplyTo((Destination) getJndiTemplate().lookup(replyToName, Destination.class)); // Setup the JmsTemplate getJmsTemplate().setConnectionFactory(connectionFactory); getJmsTemplate().setDefaultDestination(getOutput()); // Setup the default JDBC DataSource: final Document doc = getWork(inConfig); defaultDataSource.setDriverClassName(trim(doc.valueOf("//enrich/defaultDatabase/driver"))); defaultDataSource.setUrl(trim(doc.valueOf("//enrich/defaultDatabase/url"))); defaultDataSource.setUsername(trim(doc.valueOf("//enrich/defaultDatabase/username"))); defaultDataSource.setPassword(trim(doc.valueOf("//enrich/defaultDatabase/password"))); //FIXME: pool properties hard coded here defaultDataSource.setMaxActive(5); defaultDataSource.setMaxIdle(2); defaultDataSource.setMinIdle(1); jdbcTemplate = new SimpleJdbcTemplate(getDefaultDataSource()); // create list of value transforms from the elements list final List<Element> elements = doc.selectNodes("//enrich/elements/element"); for (Element node : elements) { SimpleJdbcTemplate vttemplate = jdbcTemplate; final String ddriver = node.valueOf("database/driver"); if (ddriver != null && !"".equals(ddriver)) { // normally we'll use the defaultDataSource which is a pooling source // but we give the ability to specify a unique DataSource as well final DriverManagerDataSource dmds = new DriverManagerDataSource(); dmds.setDriverClassName(trim(node.valueOf("database/driver"))); dmds.setUrl(trim(node.valueOf("database/url"))); dmds.setUsername(trim(node.valueOf("database/username"))); dmds.setPassword(trim(node.valueOf("database/password"))); vttemplate = new SimpleJdbcTemplate(dmds); } final XMLValueTransformer xvt = new XMLValueTransformer(vttemplate); xvt.setSrcPath(trim(node.valueOf("srcPath"))); xvt.setDstPath(trim(node.valueOf("dstPath"))); xvt.setSql(trim(node.valueOf("sql"))); // validates SQL statement xforms.add(xvt); } } catch (NamingException ex) { LOGGER.log(Level.SEVERE, "Bad JNDI name for Destination: " + getName(), ex); setStatus(STATUS_FAILED); } catch (DocumentException ex) { LOGGER.log(Level.SEVERE, "Invalid work XML for transform: ", ex); setStatus(STATUS_FAILED); } catch (XMLValueTransformException ex) { LOGGER.log(Level.SEVERE, "Bad work XML: ", ex); setStatus(STATUS_FAILED); } catch (SQLException ex) { LOGGER.log(Level.SEVERE, "Bad SQL query: ", ex); } }
From source file:in.sc.dao.ListGenerator.java
public NamedParameterJdbcTemplate getTemplate() { if (namedParameterJdbcTemplate == null) { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setSchema("smart_compare"); dataSource.setUsername("root"); dataSource.setPassword("root"); dataSource.setUrl("jdbc:mysql://localhost:3306/smart_compare"); // dataSource.setPassword("rose@123"); // dataSource.setURL("jdbc:mysql://52.42.111.208:3033/smart_compare"); namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); }//from ww w. j av a 2 s . co m return namedParameterJdbcTemplate; }
From source file:biz.wolschon.finance.jgnucash.mysql.MySQLDataSource.java
/** * {@inheritDoc}// ww w. j a v a 2 s.c o m * @see biz.wolschon.finance.jgnucash.plugin.DataSourcePlugin#loadFile() */ @Override public GnucashWritableFile loadFile() throws IOException, JAXBException { JOptionPane.showMessageDialog(null, "WARNING! MySQL-support is still incomplete"); try { com.mysql.jdbc.Driver driver = new com.mysql.jdbc.Driver(); //Class.forName("com.mysql.jdbc.Driver").newInstance(); // SimpleDriverDataSource dataSource = new SimpleDriverDataSource(driver, "jdbc:mysql://localhost/gnucash", "root", ""); DriverManagerDataSource dataSource = new DriverManagerDataSource(); ClassUtils.setDefaultClassLoader(getClassLoader()); try { dataSource.setDriverClassName("com.mysql.jdbc.Driver"); } catch (Exception e) { e.printStackTrace(); //ignored } dataSource.setUrl("jdbc:mysql://localhost/gnucash"); dataSource.setUsername("root"); dataSource.setPassword(""); return new GnucashDatabase(dataSource); } catch (Exception e) { LOG.log(Level.SEVERE, "Cannot open database-connection", e); } return null; }