Dynamically load a JDBC driver

Figure 917. Problem: Dynamic driver configuration Slide presentation
server=db.somedomain.org
port=3306
...
driver=mariadb-java-client-3.3.3.jar
  • Driver file mariadb-java-client-3.3.3.jar shall be loaded at runtime.

  • Cannot be packaged by manufacturer.

  • Problem: Class loader and security


Figure 918. Shim driver (facade) Slide presentation
import java.sql.Driver;
  ...
public class DriverShim implements Driver {
    private Driver driver;
    DriverShim(Driver driver) {
        this.driver = driver;
    }
    @Override
    public Connection connect(String s, Properties properties) throws SQLException {
        return driver.connect(s, properties);
    }
    @Override
    public boolean acceptsURL(String u) throws SQLException {
        return driver.acceptsURL(u);
    }
...
}