JdbcUtil { public static String getSchema(final Connection connection, final String databaseType) { String result = null; try { if ("Oracle".equals(databaseType)) { DatabaseMetaData metaData = connection.getMetaData(); if (null != metaData) { return Optional.ofNullable(metaData.getUserName()).map(String::toUpperCase).orElse(null); } else { return null; } } result = connection.getSchema(); } catch (final SQLException ignore) { } return result; }  static String getSchema(final Connection connection, final String databaseType);  }
@Test public void assertMysqlGetSchema() throws SQLException { when(connection.getSchema()).thenReturn("demo_ds"); String schema = JdbcUtil.getSchema(connection, ""); assertThat(schema, is("demo_ds")); }
@Test public void assertOracleGetSchema() { String schema = JdbcUtil.getSchema(connection, "Oracle"); assertThat(schema, is(nullValue())); }