@BeforeClass public static void setUp() { dbFile = System.getProperty("java.io.tmpdir") + File.separator + "batch_sqlite_inc.db"; dataSource = new SimpleDriverDataSource(); dataSource.setDriverClass(org.sqlite.JDBC.class); dataSource.setUrl("jdbc:sqlite:" + dbFile); template = new JdbcTemplate(dataSource); template.execute("create table max_value (id integer primary key autoincrement)"); }
@Bean("dataSource") public DataSource dataSource() { SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); dataSource.setDriverClass(com.mysql.jdbc.Driver.class); dataSource.setUrl("jdbc:mysql://localhost:3306/mybatis_plus?useSSL=false&useUnicode=true&characterEncoding=UTF-8"); dataSource.setUsername("root"); dataSource.setPassword("123456"); return dataSource; }
@Bean("dataSource") public DataSource dataSource() { SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); dataSource.setDriverClass(org.postgresql.Driver.class); dataSource.setUrl("jdbc:postgresql://localhost:5432/mybatis_plus"); dataSource.setUsername("postgres"); dataSource.setPassword("123123"); return dataSource; }
@Bean public DataSource dataSource(){ SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); dataSource.setDriver(new Driver()); dataSource.setUrl("jdbc:h2:mem:test;MODE=mysql;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE"); dataSource.setUsername("sa"); dataSource.setPassword(""); return dataSource; }
SimpleDriverDataSource simpleDriverDataSource = new SimpleDriverDataSource(); simpleDriverDataSource.setDriverClass(org.h2.Driver.class); simpleDriverDataSource.setUrl("jdbc:h2:target/database/example;AUTO_RECONNECT=TRUE");
private static DataSource newSimpleDriverDataSource(String jdbcUrl) { try { return new SimpleDriverDataSource(DriverManager.getDriver(jdbcUrl), jdbcUrl); } catch (SQLException e) { throw new RuntimeException("Unable to construct DataSource", e); } }
private static DataSource newSimpleDriverDataSource(String jdbcUrl) { try { return new SimpleDriverDataSource(DriverManager.getDriver(jdbcUrl), jdbcUrl); } catch (SQLException e) { throw new RuntimeException("Unable to construct DataSource", e); } }
SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); dataSource.setDriverClass((Class<Driver>)Class.forName("com.mysql.jdbc.Driver"));
@Configuration class DevbConfig { @Bean(name = "devbDataSource") DataSource devbDataSource() { try { return new SimpleDriverDataSource(DriverManager.getDriver("jdbc:..."), "jdbc:...", "username", "password"); } catch (SQLException e) { throw new RuntimeException(e); } } @Bean(name = "devbJdbc") JdbcTemplate devbJdbc(@Qualifier("devbDataSource") DataSource dataSource) { return new JdbcTemplate(dataSource); } }
@Bean public DataSource someDataSource() throws SQLException { final SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); dataSource.setUrl(System.getProperty("db.url")); dataSource.setUsername(System.getProperty("db.user")); dataSource.setPassword(System.getProperty("db.password")); // Driver, connection properties, if any, and other stuff return dataSource; }
protected DataSource getDataSource(ConnectionContext context, Driver driver) { Properties properties = getProperties(context); return new SimpleDriverDataSource(driver, context.getUrl(), properties); }
@Bean public DataSource dataSource() { SimpleDriverDataSource ds = new SimpleDriverDataSource(); try { @SuppressWarnings("unchecked") Class<? extends Driver> driverClass = (Class<? extends Driver>) Class.forName(environment.getProperty("jdbc.driver", "org.h2.Driver")); ds.setDriverClass(driverClass); } catch (Exception e) { log.error("Error loading driver class", e); } // Connection settings ds.setUrl(environment.getProperty("jdbc.url", "jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000")); ds.setUsername(environment.getProperty("jdbc.user", "sa")); ds.setPassword(environment.getProperty("jdbc.password", "")); return ds; }
@Configuration public class SomeConfigClass { @Autowired private Environment env; public DataSource dataSource() { SimpleDriverDataSource ds = new SimpleDriverDataSource(); ds.setUsername(env.getProperty("jdbc.username")); ds.setPassword(env.getProperty("jdbc.password")); ds.setDriverClass(Driver.class); ds.setUrl(env.getProperty("jdbc.url")); return ds; } }
public static SQLFactory createUseSimpleDateSource(Driver driver, String url, String username, String password) { SQLFactory sqlFactory = new SQLFactory(); if (url.contains("jdbc:mysql:")) { sqlFactory.setDataSourceType(DataSourceType.MY_SQL); } if (url.contains("jdbc:oracle:")) { sqlFactory.setDataSourceType(DataSourceType.ORACLE); } if (url.contains("jdbc:postgresql:")) { sqlFactory.setDataSourceType(DataSourceType.POSTGRESQL); } SimpleDriverDataSource dataSource = new SimpleDriverDataSource(driver, url, username, password); sqlFactory.setDataSource(dataSource); return sqlFactory; }
@Bean(name="dataSourceRedshift") public DataSource dataSourceRedshift() throws SQLException, JSchException { SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); dataSource.setDriver(new com.amazon.redshift.jdbc41.Driver()); dataSource.setUrl("jdbc:postgresql://" + redshiftHost + ":" + redshiftPort + "/" + redshiftDatabase); dataSource.setUsername(redshiftUser); dataSource.setPassword(redshiftPass); DefaultSessionFactory defaultSessionFactory = new DefaultSessionFactory(); TunneledDataSourceWrapper tunneledDataSource = new TunneledDataSourceWrapper( new TunnelConnectionManager( defaultSessionFactory, redshiftTunnel ), dataSource ); return tunneledDataSource; }
@Configuration public class SomeConfigClass { @Value("${jdbc.username}") private String username; @Value("${jdbc.password}") private String password; @Value("${jdbc.url}") private String url public DataSource dataSource() { SimpleDriverDataSource ds = new SimpleDriverDataSource(); ds.setUsername(username); ds.setPassword(password); ds.setDriverClass(Driver.class); ds.setUrl(url); return ds; } }
@Override public DataSource create(SI serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { try { DataSource ds = createPooledDataSource(serviceInfo, serviceConnectorConfig); if (ds != null) { return ds; } // Only for testing outside Tomcat/CloudFoundry logger.warning("No connection pooling DataSource implementation found on the classpath - no pooling is in effect."); return new SimpleDriverDataSource(DriverManager.getDriver(serviceInfo.getJdbcUrl()), serviceInfo.getJdbcUrl()); } catch (Exception e) { throw new ServiceConnectorCreationException( "Failed to created cloud datasource for " + serviceInfo.getId() + " service", e); } }
@Override public DataSource create(SI serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { try { for (PooledDataSourceCreator<SI> delegate: pooledDataSourceCreators) { DataSource ds = delegate.create(serviceInfo, serviceConnectorConfig, getDriverClassName(serviceInfo), validationQuery); if (ds != null) { return ds; } } // Only for testing outside Tomcat/CloudFoundry logger.warning("Found neither DBCP nor Tomcat connection pool on the classpath (no pooling is in effect)."); return new SimpleDriverDataSource(DriverManager.getDriver(serviceInfo.getJdbcUrl()), serviceInfo.getJdbcUrl()); } catch (Exception e) { throw new ServiceConnectorCreationException( "Failed to created cloud datasource for " + serviceInfo.getId() + " service", e); } }
private void createDataSource() throws IOException, SQLException { dataSource = new SimpleDriverDataSource( Driver.load(), "jdbc:h2:mem:test" + currentTimeMillis() + ";DB_CLOSE_DELAY=-1", "sa", "" ); populateDataSource(); }
@Test public void simpleDataSourceUrl() { SimpleDriverDataSource dataSource = new SimpleDriverDataSource(Driver.load(), "jdbc:test-url"); assertEquals("jdbc:test-url", this.dataSourceUtils.getUrl(dataSource)); }