List of usage examples for org.springframework.jdbc.datasource DriverManagerDataSource setUrl
public void setUrl(@Nullable String url)
From source file:py.una.pol.karaku.test.configuration.TransactionTestConfiguration.java
/** * Crea un datasource para una base de datos embebida. * // w w w .jav a 2 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.github.fedorchuck.webstore.dao.impl.postgresql.JdbcCommodityRepositoryTest.java
@Before @Ignore//from w ww. java 2s .c om public void setUp() { try { //TODO: should be rewritten. DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(Config.DRIVERCLASSNAME); dataSource.setUrl(Config.URL); dataSource.setUsername(Config.USERNAME); dataSource.setPassword(Config.PASSWORD); jdbc = new JdbcCommodityRepository(new JdbcTemplate(dataSource)); //TODO: run creating scripts. Assert.assertTrue(true); } catch (Throwable throwable) { Assert.fail(throwable.getMessage()); } }
From source file:com.dhenton9000.birt.configs.DatabaseConfig.java
@Bean public DataSource dataSource() { URI dbUrl = null;/*from w w w .j a v a 2 s . c o m*/ 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.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 www . j a v a 2 s . c o 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.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. *//*w w w . j ava 2 s. co m*/ 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:biz.wolschon.finance.jgnucash.mysql.MySQLDataSource.java
/** * {@inheritDoc}/* w w w. jav a 2s . 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; }
From source file:com.mycompany.projetsportmanager.spring.configuration.H2ProfileConfiguration.java
/** * Builds a JNDI datasource./*from w w w . ja v a 2 s. co 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:gov.nih.nci.security.util.ConfigurationHelper.java
private DataSource getDataSourceFromDocument(Document hibernateConfigDoc) throws CSConfigurationException { Element hbnConfigElement = hibernateConfigDoc.getRootElement(); DataSource ds = null;/* w w w . j a v a 2 s .c o m*/ org.jdom.Element urlProperty = null, usernameProperty = null, passwordProperty = null, driverProperty = null; try { org.jdom.Element dataSourceProperty = (org.jdom.Element) XPath.selectSingleNode(hibernateConfigDoc, "/hibernate-configuration//session-factory//property[@name='connection.datasource']"); if (dataSourceProperty != null && dataSourceProperty.getTextTrim() != null) { try { InitialContext initialContext = new InitialContext(); ds = (DataSource) initialContext.lookup(dataSourceProperty.getTextTrim()); } catch (NamingException ex) { ex.printStackTrace(); throw new CSConfigurationException(); } } else { urlProperty = (org.jdom.Element) XPath.selectSingleNode(hibernateConfigDoc, "/hibernate-configuration//session-factory//property[@name='connection.url']"); usernameProperty = (org.jdom.Element) XPath.selectSingleNode(hibernateConfigDoc, "/hibernate-configuration//session-factory//property[@name='connection.username']"); passwordProperty = (org.jdom.Element) XPath.selectSingleNode(hibernateConfigDoc, "/hibernate-configuration//session-factory//property[@name='connection.password']"); driverProperty = (org.jdom.Element) XPath.selectSingleNode(hibernateConfigDoc, "/hibernate-configuration//session-factory//property[@name='connection.driver_class']"); DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(driverProperty.getTextTrim()); dataSource.setUrl(urlProperty.getTextTrim()); dataSource.setUsername(usernameProperty.getTextTrim()); dataSource.setPassword(passwordProperty.getTextTrim()); ds = dataSource; } } catch (JDOMException e) { e.printStackTrace(); throw new CSConfigurationException(); } return ds; }
From source file:com.unito.repository.JDBCConfig.java
@Bean public DataSource dataSource() { DriverManagerDataSource driverManager = new DriverManagerDataSource(); //driverManager.setDriverClassName("org.apache.derby.jdbc.EmbeddedDriver"); //driverManager.setDriverClassName(new org.apache.derby.jdbc.EmbeddedDriver()); //driverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver()); driverManager.setDriverClassName("com.mysql.jdbc.Driver"); //create=true - start db derby server driverManager.setUrl("jdbc:mysql://podgoreanu.ddns.net:3306/mysql"); driverManager.setUsername("root"); driverManager.setPassword("645128"); return driverManager; }