org.apache.commons.dbcp.BasicDataSource Java Examples
The following examples show how to use
org.apache.commons.dbcp.BasicDataSource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BootstrapEnvironment.java From shardingsphere-elasticjob-cloud with Apache License 2.0 | 7 votes |
/** * Get the job event rdb config. * * @return job event rdb config */ public Optional<JobEventRdbConfiguration> getJobEventRdbConfiguration() { String driver = getValue(EnvironmentArgument.EVENT_TRACE_RDB_DRIVER); String url = getValue(EnvironmentArgument.EVENT_TRACE_RDB_URL); String username = getValue(EnvironmentArgument.EVENT_TRACE_RDB_USERNAME); String password = getValue(EnvironmentArgument.EVENT_TRACE_RDB_PASSWORD); if (!Strings.isNullOrEmpty(driver) && !Strings.isNullOrEmpty(url) && !Strings.isNullOrEmpty(username)) { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(driver); dataSource.setUrl(url); dataSource.setUsername(username); dataSource.setPassword(password); return Optional.of(new JobEventRdbConfiguration(dataSource)); } return Optional.absent(); }
Example #2
Source File: DynamicDBUtil.java From teaching with Apache License 2.0 | 6 votes |
/** * 获取数据源【最底层方法,不要随便调用】 * * @param dbSource * @return */ @Deprecated private static BasicDataSource getJdbcDataSource(final DynamicDataSourceModel dbSource) { BasicDataSource dataSource = new BasicDataSource(); String driverClassName = dbSource.getDbDriver(); String url = dbSource.getDbUrl(); String dbUser = dbSource.getDbUsername(); String dbPassword = dbSource.getDbPassword(); //设置数据源的时候,要重新解密 // String dbPassword = PasswordUtil.decrypt(dbSource.getDbPassword(), dbSource.getDbUsername(), PasswordUtil.getStaticSalt());//解密字符串; dataSource.setDriverClassName(driverClassName); dataSource.setUrl(url); dataSource.setUsername(dbUser); dataSource.setPassword(dbPassword); return dataSource; }
Example #3
Source File: MysqlStateStore.java From incubator-gobblin with Apache License 2.0 | 6 votes |
/** * creates a new {@link BasicDataSource} * @param config the properties used for datasource instantiation * @return */ public static BasicDataSource newDataSource(Config config) { BasicDataSource basicDataSource = new BasicDataSource(); PasswordManager passwordManager = PasswordManager.getInstance(ConfigUtils.configToProperties(config)); basicDataSource.setDriverClassName(ConfigUtils.getString(config, ConfigurationKeys.STATE_STORE_DB_JDBC_DRIVER_KEY, ConfigurationKeys.DEFAULT_STATE_STORE_DB_JDBC_DRIVER)); // MySQL server can timeout a connection so need to validate connections before use basicDataSource.setValidationQuery("select 1"); basicDataSource.setTestOnBorrow(true); basicDataSource.setDefaultAutoCommit(false); basicDataSource.setTimeBetweenEvictionRunsMillis(60000); basicDataSource.setUrl(config.getString(ConfigurationKeys.STATE_STORE_DB_URL_KEY)); basicDataSource.setUsername(passwordManager.readPassword( config.getString(ConfigurationKeys.STATE_STORE_DB_USER_KEY))); basicDataSource.setPassword(passwordManager.readPassword( config.getString(ConfigurationKeys.STATE_STORE_DB_PASSWORD_KEY))); basicDataSource.setMinEvictableIdleTimeMillis( ConfigUtils.getLong(config, ConfigurationKeys.STATE_STORE_DB_CONN_MIN_EVICTABLE_IDLE_TIME_KEY, ConfigurationKeys.DEFAULT_STATE_STORE_DB_CONN_MIN_EVICTABLE_IDLE_TIME)); return basicDataSource; }
Example #4
Source File: MockInitialContextFactory.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Destroy the initial context. */ public static void destroy() { Map<String, Object> jndiObjectsMap = jndiContextData.get(); if (jndiObjectsMap != null) { for (Map.Entry entry : jndiObjectsMap.entrySet()) { Object value = entry.getValue(); if (value != null && value instanceof BasicDataSource) { try { ((BasicDataSource) value).close(); } catch (SQLException e) { //Just Ignore for now. } } } jndiContextData.remove(); } }
Example #5
Source File: MysqlDataSourceFactoryTest.java From incubator-gobblin with Apache License 2.0 | 6 votes |
@Test public void testDifferentKey() throws IOException { Config config1 = ConfigFactory.parseMap(ImmutableMap.of(ConfigurationKeys.STATE_STORE_DB_URL_KEY, "url1", ConfigurationKeys.STATE_STORE_DB_USER_KEY, "user", ConfigurationKeys.STATE_STORE_DB_PASSWORD_KEY, "dummypwd")); Config config2 = ConfigFactory.parseMap(ImmutableMap.of(ConfigurationKeys.STATE_STORE_DB_URL_KEY, "url2", ConfigurationKeys.STATE_STORE_DB_USER_KEY, "user", ConfigurationKeys.STATE_STORE_DB_PASSWORD_KEY, "dummypwd")); BasicDataSource basicDataSource1 = MysqlDataSourceFactory.get(config1, SharedResourcesBrokerFactory.getImplicitBroker()); BasicDataSource basicDataSource2 = MysqlDataSourceFactory.get(config2, SharedResourcesBrokerFactory.getImplicitBroker()); Assert.assertNotEquals(basicDataSource1, basicDataSource2); }
Example #6
Source File: BasicAuthJDBCTest.java From apiman with Apache License 2.0 | 6 votes |
/** * Creates an in-memory datasource. * @throws SQLException */ private static BasicDataSource createInMemoryDatasource() throws SQLException { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(Driver.class.getName()); ds.setUsername("sa"); //$NON-NLS-1$ ds.setPassword(""); //$NON-NLS-1$ ds.setUrl("jdbc:h2:mem:BasicAuthJDBCTest;DB_CLOSE_DELAY=-1"); //$NON-NLS-1$ Connection connection = ds.getConnection(); connection.prepareStatement("CREATE TABLE users ( username varchar(255) NOT NULL, password varchar(255) NOT NULL, PRIMARY KEY (username))").executeUpdate(); connection.prepareStatement("INSERT INTO users (username, password) VALUES ('bwayne', 'ae2efd698aefdf366736a4eda1bc5241f9fbfec7')").executeUpdate(); connection.prepareStatement("INSERT INTO users (username, password) VALUES ('ckent', 'ea59f7ca52a2087c99374caba0ff29be1b2dcdbf')").executeUpdate(); connection.prepareStatement("INSERT INTO users (username, password) VALUES ('ballen', 'ea59f7ca52a2087c99374caba0ff29be1b2dcdbf')").executeUpdate(); connection.prepareStatement("CREATE TABLE roles (rolename varchar(255) NOT NULL, username varchar(255) NOT NULL)").executeUpdate(); connection.prepareStatement("INSERT INTO roles (rolename, username) VALUES ('user', 'bwayne')").executeUpdate(); connection.prepareStatement("INSERT INTO roles (rolename, username) VALUES ('admin', 'bwayne')").executeUpdate(); connection.prepareStatement("INSERT INTO roles (rolename, username) VALUES ('ckent', 'user')").executeUpdate(); connection.prepareStatement("INSERT INTO roles (rolename, username) VALUES ('ballen', 'user')").executeUpdate(); connection.close(); return ds; }
Example #7
Source File: JDBCDataSourceProvider.java From eagle with Apache License 2.0 | 6 votes |
@Override public DataSource get() { BasicDataSource datasource = new BasicDataSource(); datasource.setDriverClassName(config.getDriverClassName()); datasource.setUsername(config.getUsername()); datasource.setPassword(config.getPassword()); datasource.setUrl(config.getConnection()); datasource.setConnectionProperties(config.getConnectionProperties()); LOGGER.info("Register JDBCDataSourceShutdownHook"); Runtime.getRuntime().addShutdownHook(new Thread("JDBCDataSourceShutdownHook") { @Override public void run() { try { LOGGER.info("Shutting down data source"); datasource.close(); } catch (SQLException e) { LOGGER.error("SQLException: {}", e.getMessage(), e); throw new IllegalStateException("Failed to close datasource", e); } } }); return datasource; }
Example #8
Source File: PersistService.java From diamond with Apache License 2.0 | 6 votes |
@PostConstruct public void initDataSource() throws Exception { // 读取jdbc.properties配置, 加载数据源 Properties props = ResourceUtils.getResourceAsProperties("jdbc.properties"); BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(JDBC_DRIVER_NAME); ds.setUrl(ensurePropValueNotNull(props.getProperty("db.url"))); ds.setUsername(ensurePropValueNotNull(props.getProperty("db.user"))); ds.setPassword(ensurePropValueNotNull(props.getProperty("db.password"))); ds.setInitialSize(Integer.parseInt(ensurePropValueNotNull(props.getProperty("db.initialSize")))); ds.setMaxActive(Integer.parseInt(ensurePropValueNotNull(props.getProperty("db.maxActive")))); ds.setMaxIdle(Integer.parseInt(ensurePropValueNotNull(props.getProperty("db.maxIdle")))); ds.setMaxWait(Long.parseLong(ensurePropValueNotNull(props.getProperty("db.maxWait")))); ds.setPoolPreparedStatements(Boolean.parseBoolean(ensurePropValueNotNull(props .getProperty("db.poolPreparedStatements")))); this.jt = new JdbcTemplate(); this.jt.setDataSource(ds); // 设置最大记录数,防止内存膨胀 this.jt.setMaxRows(MAX_ROWS); // 设置JDBC执行超时时间 this.jt.setQueryTimeout(QUERY_TIMEOUT); }
Example #9
Source File: JDBCPersistenceProvider.java From oxd with Apache License 2.0 | 6 votes |
@Override public void onCreate() { try { JDBCConfiguration jdbcConfiguration = asJDBCConfiguration(configurationService.getConfiguration()); validate(jdbcConfiguration); dataSource = new BasicDataSource(); dataSource.setDriverClassName(jdbcConfiguration.getDriver()); dataSource.setUrl(jdbcConfiguration.getJdbcUrl()); dataSource.setUsername(jdbcConfiguration.getUsername()); dataSource.setPassword(jdbcConfiguration.getPassword()); dataSource.setMinIdle(5); dataSource.setMaxIdle(10); dataSource.setMaxOpenPreparedStatements(100); } catch (Exception e) { LOG.error("Error in creating jdbc connection.", e); throw new RuntimeException(e); } }
Example #10
Source File: JdbcPushDownConnectionManager.java From kylin with Apache License 2.0 | 6 votes |
private JdbcPushDownConnectionManager(KylinConfig config, String id) throws ClassNotFoundException { dataSource = new BasicDataSource(); Class.forName(config.getJdbcDriverClass(id)); dataSource.setDriverClassName(config.getJdbcDriverClass(id)); dataSource.setUrl(config.getJdbcUrl(id)); dataSource.setUsername(config.getJdbcUsername(id)); dataSource.setPassword(config.getJdbcPassword(id)); dataSource.setMaxActive(config.getPoolMaxTotal(id)); dataSource.setMaxIdle(config.getPoolMaxIdle(id)); dataSource.setMinIdle(config.getPoolMinIdle(id)); // Default settings dataSource.setTestOnBorrow(true); dataSource.setValidationQuery("select 1"); dataSource.setRemoveAbandoned(true); dataSource.setRemoveAbandonedTimeout(300); }
Example #11
Source File: DataSourceProvider.java From incubator-gobblin with Apache License 2.0 | 6 votes |
@Inject public DataSourceProvider(@Named("dataSourceProperties") Properties properties) { this.basicDataSource = new BasicDataSource(); this.basicDataSource.setDriverClassName(properties.getProperty(CONN_DRIVER, DEFAULT_CONN_DRIVER)); this.basicDataSource.setUrl(properties.getProperty(CONN_URL)); if (properties.containsKey(USERNAME) && properties.containsKey(PASSWORD)) { this.basicDataSource.setUsername(properties.getProperty(USERNAME)); this.basicDataSource .setPassword(PasswordManager.getInstance(properties).readPassword(properties.getProperty(PASSWORD))); } if (properties.containsKey(MAX_IDLE_CONNS)) { this.basicDataSource.setMaxIdle(Integer.parseInt(properties.getProperty(MAX_IDLE_CONNS))); } if (properties.containsKey(MAX_ACTIVE_CONNS)) { this.basicDataSource.setMaxActive(Integer.parseInt(properties.getProperty(MAX_ACTIVE_CONNS))); } }
Example #12
Source File: MysqlDagStateStoreTest.java From incubator-gobblin with Apache License 2.0 | 6 votes |
@Override protected StateStore<State> createStateStore(Config config) { try { // Setting up mock DB ITestMetastoreDatabase testMetastoreDatabase = TestMetastoreDatabaseFactory.get(); String jdbcUrl = testMetastoreDatabase.getJdbcUrl(); BasicDataSource mySqlDs = new BasicDataSource(); mySqlDs.setDriverClassName(ConfigurationKeys.DEFAULT_STATE_STORE_DB_JDBC_DRIVER); mySqlDs.setDefaultAutoCommit(false); mySqlDs.setUrl(jdbcUrl); mySqlDs.setUsername(TEST_USER); mySqlDs.setPassword(TEST_PASSWORD); return new MysqlStateStore<>(mySqlDs, TEST_DAG_STATE_STORE, false, State.class); } catch (Exception e) { throw new RuntimeException(e); } }
Example #13
Source File: TestTaskBase.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Returns an instance of the {@link DdlToDatabaseTask}, already configured with * a project and the tested database. * * @return The task object */ protected DdlToDatabaseTask getDdlToDatabaseTaskInstance() { DdlToDatabaseTask task = new DdlToDatabaseTask(); Properties props = getTestProperties(); String catalog = props.getProperty(DDLUTILS_CATALOG_PROPERTY); String schema = props.getProperty(DDLUTILS_SCHEMA_PROPERTY); DataSource dataSource = getDataSource(); if (!(dataSource instanceof BasicDataSource)) { fail("Datasource needs to be of type " + BasicDataSource.class.getName()); } task.setProject(new Project()); task.addConfiguredDatabase((BasicDataSource)getDataSource()); task.setCatalogPattern(catalog); task.setSchemaPattern(schema); task.setUseDelimitedSqlIdentifiers(isUseDelimitedIdentifiers()); return task; }
Example #14
Source File: ExecutionStateRepositoryTest.java From score with Apache License 2.0 | 5 votes |
@Bean DataSource dataSource() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("org.h2.Driver"); ds.setUrl("jdbc:h2:mem:test"); ds.setUsername("sa"); ds.setPassword("sa"); ds.setDefaultAutoCommit(false); return ds; }
Example #15
Source File: DbcpDatabasePropertiesReteriver.java From compass with Apache License 2.0 | 5 votes |
@Override public int getMaxConnectionsNumber(DataSource dataSource) { try { BasicDataSource ds = (BasicDataSource)dataSource; return ds.getMaxActive(); } catch (Exception e) { if(logger.isDebugEnabled()){ logger.info(" query DBCP datasource="+dataSource+" max connections number fail"); } return IllegalNumber; } }
Example #16
Source File: DataStoreBaseTest.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
protected void initH2DB(String databaseName, String scriptPath) throws Exception { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.h2.Driver"); dataSource.setUsername("username"); dataSource.setPassword("password"); dataSource.setUrl("jdbc:h2:mem:test" + databaseName); try (Connection connection = dataSource.getConnection()) { connection.createStatement().executeUpdate("RUNSCRIPT FROM '" + scriptPath + "'"); } dataSourceMap.put(databaseName, dataSource); }
Example #17
Source File: ValidationProfilesResourceTest.java From apicurio-studio with Apache License 2.0 | 5 votes |
/** * Creates an in-memory datasource. * @throws SQLException */ private static BasicDataSource createInMemoryDatasource() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(Driver.class.getName()); ds.setUsername("sa"); ds.setPassword(""); ds.setUrl("jdbc:h2:mem:vptest" + (counter++) + ";DB_CLOSE_DELAY=-1"); return ds; }
Example #18
Source File: MysqlDatasetStateStoreTest.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@BeforeClass public void setUp() throws Exception { testMetastoreDatabase = TestMetastoreDatabaseFactory.get(); String jdbcUrl = testMetastoreDatabase.getJdbcUrl(); ConfigBuilder configBuilder = ConfigBuilder.create(); BasicDataSource mySqlDs = new BasicDataSource(); mySqlDs.setDriverClassName(ConfigurationKeys.DEFAULT_STATE_STORE_DB_JDBC_DRIVER); mySqlDs.setDefaultAutoCommit(false); mySqlDs.setUrl(jdbcUrl); mySqlDs.setUsername(TEST_USER); mySqlDs.setPassword(TEST_PASSWORD); dbJobStateStore = new MysqlStateStore<>(mySqlDs, TEST_STATE_STORE, false, JobState.class); configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_URL_KEY, jdbcUrl); configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_USER_KEY, TEST_USER); configBuilder.addPrimitive(ConfigurationKeys.STATE_STORE_DB_PASSWORD_KEY, TEST_PASSWORD); ClassAliasResolver<DatasetStateStore.Factory> resolver = new ClassAliasResolver<>(DatasetStateStore.Factory.class); DatasetStateStore.Factory stateStoreFactory = resolver.resolveClass("mysql").newInstance(); dbDatasetStateStore = stateStoreFactory.createStateStore(configBuilder.build()); // clear data that may have been left behind by a prior test run dbJobStateStore.delete(TEST_JOB_NAME); dbDatasetStateStore.delete(TEST_JOB_NAME); dbJobStateStore.delete(TEST_JOB_NAME2); dbDatasetStateStore.delete(TEST_JOB_NAME2); }
Example #19
Source File: DataStoreBaseTest.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
public static BasicDataSource getDatasource(String datasourceName) { if (dataSourceMap.get(datasourceName) != null) { return dataSourceMap.get(datasourceName); } throw new RuntimeException("No datasource initiated for database: " + datasourceName); }
Example #20
Source File: DbcpDatabasePropertiesReteriver.java From compass with Apache License 2.0 | 5 votes |
@Override public int getBusyConnectionsNumber(DataSource dataSource) { try { BasicDataSource ds = (BasicDataSource)dataSource; return ds.getNumActive(); } catch (Exception e) { if(logger.isDebugEnabled()){ logger.debug(" query DBCP datasource="+dataSource+" busy connections number fail"); } return IllegalNumber; } }
Example #21
Source File: MockInitialContextFactory.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
private static BasicDataSource getDatasource(String name) { Map context = jndiContextData.get(); if (context == null) { return null; } return (BasicDataSource) context.get(name); }
Example #22
Source File: GfxdDdlUtils.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
protected void executeWriteDataDtdToFile(final CommandLine cmdLine, final String cmd, final String cmdDescKey) throws ParseException, SQLException { String dtdFileName = null; final DataSourceOptions dsOpts = new DataSourceOptions(); String verbosity = null; Iterator<?> iter = cmdLine.iterator(); GfxdOption opt; while (iter.hasNext()) { opt = (GfxdOption)iter.next(); if (!handleDataSourceOption(opt, dsOpts) && !handleCommonOption(opt, cmd, cmdDescKey)) { if (FILE_NAME.equals(opt.getOpt())) { dtdFileName = opt.getValue(); } else { verbosity = handleVerbosityOption(opt); } } } BasicDataSource dataSource = handleDataSourceOptions(dsOpts, cmd, cmdDescKey); final DatabaseToDdlTask fromDBTask = new DatabaseToDdlTask(); if (verbosity != null) { fromDBTask.setVerbosity(new VerbosityLevel(verbosity)); } fromDBTask.addConfiguredDatabase(dataSource); WriteDtdToFileCommand writeDtdToFile = new WriteDtdToFileCommand(); File dtdFile = new File(dtdFileName); writeDtdToFile.setFailOnError(true); writeDtdToFile.setOutputFile(dtdFile); fromDBTask.addWriteDtdToFile(writeDtdToFile); fromDBTask.execute(); }
Example #23
Source File: DAOUtils.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
public static void initializeDataSource(String databaseName, String scriptPath) throws Exception { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.h2.Driver"); dataSource.setUsername("username"); dataSource.setPassword("password"); dataSource.setUrl("jdbc:h2:mem:" + databaseName); try (Connection connection = dataSource.getConnection()) { connection.createStatement().executeUpdate("RUNSCRIPT FROM '" + scriptPath + "'"); } dataSourceMap.put(databaseName, dataSource); }
Example #24
Source File: PersistenceConfig.java From batchers with Apache License 2.0 | 5 votes |
@Bean public DataSource dataSource() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName(driverClassName); ds.setUrl(url); ds.setUsername(user); ds.setPassword(password); ds.setDefaultAutoCommit(false); return ds; }
Example #25
Source File: PartitionTemplateWithEmfTest.java From score with Apache License 2.0 | 5 votes |
@Bean DataSource dataSource() { BasicDataSource ds = new BasicDataSource(); ds.setDriverClassName("org.h2.Driver"); ds.setUrl("jdbc:h2:mem:test"); ds.setUsername("sa"); ds.setPassword("sa"); ds.setDefaultAutoCommit(false); return new TransactionAwareDataSourceProxy(ds); }
Example #26
Source File: RDBStatisticRepositoryTest.java From shardingsphere-elasticjob-lite with Apache License 2.0 | 5 votes |
@Before public void setup() throws SQLException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(org.h2.Driver.class.getName()); dataSource.setUrl("jdbc:h2:mem:"); dataSource.setUsername("sa"); dataSource.setPassword(""); repository = new RDBStatisticRepository(dataSource); }
Example #27
Source File: MysqlDataSourceFactory.java From incubator-gobblin with Apache License 2.0 | 5 votes |
@Override public SharedResourceFactoryResponse<BasicDataSource> createResource(SharedResourcesBroker<S> broker, ScopedConfigView<S, MysqlDataSourceKey> config) throws NotConfiguredException { MysqlDataSourceKey key = config.getKey(); Config configuration = key.getConfig(); BasicDataSource dataSource = MysqlStateStore.newDataSource(configuration); return new ResourceInstance<>(dataSource); }
Example #28
Source File: JobEventRdbSearchTest.java From shardingsphere-elasticjob-cloud with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUpClass() throws SQLException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(org.h2.Driver.class.getName()); dataSource.setUrl("jdbc:h2:mem:"); dataSource.setUsername("sa"); dataSource.setPassword(""); storage = new JobEventRdbStorage(dataSource); repository = new JobEventRdbSearch(dataSource); initStorage(); }
Example #29
Source File: TestDataSourceBuilder.java From quickperf with Apache License 2.0 | 5 votes |
public DataSource build() { int randomInt = Math.abs(ThreadLocalRandom.current().nextInt()); String url = "jdbc:h2:mem:test" + randomInt; BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.h2.Driver"); dataSource.setUrl(url); dataSource.setUsername("qp"); dataSource.setPassword(""); dataSource.setMaxActive(4); dataSource.setPoolPreparedStatements(true); return dataSource; }
Example #30
Source File: TestUtils.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * Initiate an H2 database. * * @throws Exception */ public static void initiateH2Base() throws Exception { BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName("org.h2.Driver"); dataSource.setUsername("username"); dataSource.setPassword("password"); dataSource.setUrl("jdbc:h2:mem:test" + DB_NAME); try (Connection connection = dataSource.getConnection()) { connection.createStatement().executeUpdate("RUNSCRIPT FROM '" + getFilePath(H2_SCRIPT_NAME) + "'"); } dataSourceMap.put(DB_NAME, dataSource); }