Spring - dynamically register drivers

96 views Asked by At

I want to pick drivers at runtime - for example I might have multiple versions of mysql driver jars loaded at compile time but want to select a specific version of driver.

I found http://www.kfu.com/~nsayer/Java/dyn-jdbc.html article helpful, please help me in translating the same with Spring.

    URL u = new URL("jar:file:/path/to/pgjdbc2.jar!/");
    String classname = "org.postgresql.Driver";
    URLClassLoader ucl = new URLClassLoader(new URL[] { u });
    Driver d = (Driver)Class.forName(classname, true, ucl).newInstance();
    DriverManager.registerDriver(new DriverShim(d));
    DriverManager.getConnection("jdbc:postgresql://host/db", "user", "pw");
0

There are 0 answers