JTDSDataSourceFactory implements DataSourceFactory { Map<String, String> parseUrl(String url) { Map<String, String> result = new HashMap<>(); if (url == null || url.trim().isEmpty()) { return result; } if (!url.toLowerCase().startsWith("jdbc:jtds:")) { return result; } try { DriverPropertyInfo[] propInfo = new Driver().getPropertyInfo(url, null); for (DriverPropertyInfo info : propInfo) { result.put(info.name, info.value); } return result; } catch (SQLException e) { return result; } } JTDSDataSourceFactory(); @Override JtdsDataSource createDataSource(Properties props); @Override JtdsDataSource createConnectionPoolDataSource(Properties props); @Override JtdsDataSource createXADataSource(Properties props); @Override Driver createDriver(Properties props);  }
@Test public void testParseUrl() throws Exception { JTDSDataSourceFactory dsf = new JTDSDataSourceFactory(); Map<String, String> result = dsf.parseUrl(null); assertTrue(result.isEmpty()); result = dsf.parseUrl(""); assertTrue(result.isEmpty()); result = dsf.parseUrl("jdbc:bla"); assertTrue(result.isEmpty()); result = dsf.parseUrl("jdbc:jtds:sqlserver assertTrue(result.isEmpty()); result = dsf.parseUrl("jdbc:jtds:sqlserver: assertEquals("1", result.get("SERVERTYPE")); assertEquals("host", result.get("SERVERNAME")); result = dsf.parseUrl("jdbc:jtds:sqlserver: assertEquals("1", result.get("SERVERTYPE")); assertEquals("host", result.get("SERVERNAME")); assertEquals("1433", result.get("PORTNUMBER")); assertEquals("testdb", result.get("DATABASENAME")); result = dsf.parseUrl("jdbc:jtds:sqlserver: assertEquals("1", result.get("SERVERTYPE")); assertEquals("host", result.get("SERVERNAME")); assertEquals("1434", result.get("PORTNUMBER")); assertEquals("bla", result.get("DATABASENAME")); assertEquals("Test", result.get("APPNAME")); }