List of usage examples for org.springframework.jdbc.datasource DriverManagerDataSource setDriverClassName
public void setDriverClassName(String driverClassName)
From source file:org.beangle.ems.database.service.DatasourceService.java
public DataSource getDatasource(Integer id) { DataSource datasource = datasources.get(id); if (null == datasource) { OqlBuilder<DatasourceBean> builder = OqlBuilder.from(DatasourceBean.class, "ds"); builder.where("ds.id=:id", id); List<DatasourceBean> beans = entityDao.search(builder); if (!beans.isEmpty()) { DatasourceBean bean = beans.get(0); DriverManagerDataSource ds = new DriverManagerDataSource(); ds.setUrl(bean.getUrl());//from w w w . j av a 2 s . com ds.setUsername(bean.getUsername()); ds.setPassword(bean.getPassword()); ds.setDriverClassName(bean.getDriverClassName()); Properties properties = new Properties(); for (DatasourcePropertyBean propertyBean : bean.getProperties()) { properties.put(propertyBean.getName(), propertyBean.getValue()); } ds.setConnectionProperties(properties); datasource = ds; } datasources.put(id, datasource); } return datasource; }
From source file:com.fantasy.AggregatorConfig.java
@Bean public DataSource dataSource() { DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("org.postgresql.Driver"); dataSource.setUrl("jdbc:postgresql://localhost:5432/fantasy"); dataSource.setUsername("postgres"); dataSource.setPassword("notorious"); return dataSource; }
From source file:biz.wolschon.finance.jgnucash.mysql.MySQLDataSource.java
/** * {@inheritDoc}//from www .ja va 2 s. c om * @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: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:com.github.fedorchuck.webstore.dao.impl.postgresql.JdbcCommodityRepositoryTest.java
@Before @Ignore//from ww w . jav a 2 s .c o m 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.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 ww w . ja 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:org.mitre.jdbc.datasource.H2DataSourceFactory.java
protected DataSource createDataSource() { DriverManagerDataSource ds = new DriverManagerDataSource(); ds.setDriverClassName("org.h2.Driver"); ds.setUrl(getConnectionString());//from w w w . j a va 2 s . c om ds.setUsername("sa"); ds.setPassword(""); logger.debug("Created dataSource: " + ds.toString()); 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; }
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 ww . ja v a 2 s . com*/ 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); } }