OracleJarUtils { public static DataSource createOracleDataSource(String uri) throws Exception { DataSource ds = null; try { Class oracleDataSourceClass = loadClass("oracle.jdbc.pool.OracleDataSource"); Object ods = oracleDataSourceClass.newInstance(); ds = (DataSource) ods; Method setURLMethod = oracleDataSourceClass.getMethod("setURL", String.class); Method getConnectionPropertiesMethod = oracleDataSourceClass.getMethod("getConnectionProperties"); Method setConnectionPropertiesMethod = oracleDataSourceClass.getMethod("setConnectionProperties", Properties.class); setURLMethod.invoke(ods, uri); Properties prop = (Properties) getConnectionPropertiesMethod.invoke(ods); if (prop == null) { prop = new Properties(); } setConnectionPropertiesMethod.invoke(ods, prop); } catch (Exception e) { String errMsg = "Error trying to create an Oracle DataSource"; LOG.error(errMsg, e); throw e; } return ds; }  static DataSource createOracleDataSource(String uri); static Class loadClass(String className);  }
@Test public void testCreateOracleDataSource() throws Exception { DataSource ds1 = OracleJarUtils.createOracleDataSource("jdbc:oracle:thin:person/person@devdb:1521:db"); DataSource ds2 = OracleJarUtils.createOracleDataSource("jdbc:oracle:thin:person/person@devdb:1521:db"); boolean isEqual = ds1.equals(ds2); Assert.assertEquals(isEqual, false); boolean isIdentical = (ds1 == ds2); Assert.assertEquals(isIdentical, false); }