
Connecting a database with dynamically loaded jar file
Last Update: 19.05.2009
{
    String driver="com.mysql.jdbc.Driver";
    String
jarFile="C:/Tmp/mysql-connector-java-5.1.7-bin.jar";
    try
    {
       File file=new File(jarFile);
       ucl = new URLClassLoader(new
URL[]{file.toURI().toURL()});
       Class<?> driverClass=null;
       driverclass=ucl.loadClass(driver);
       Class.forName(driver, true, ucl);
       Driver
thedriver=(Driver)(driverclass.newInstance());
       Properties info=new Properties();
       if(username!=null)
          info.put("user",username);
       if(password!=null)
         
info.put("password",password);
       con=thedriver.connect(url,info);
    }
    catch(MalformedURLException e)
    {
    }
}