• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

loading JDBC driver from a Jar (not in classpath)

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can one load a JDBC driver from a Jar file that is not in the classpath?
Currently the Jar's (with the db driver) location is indicated in the run script. However, the application should be deployed as a Jar file, so that the user could start it just by executing that Jar file. The problem is that the user could use any jdbc driver that could be located anywhere on the machine, so I cannot hardcode it, and have to ask the user to provide this information.
How can I load the driver after the user has given the Jar location and driver name (it is a Swing application).
Right now the driver is loaded and connection established by:

I was trying to use a URLClassLoader, but aparently am missing some step:

Thanks for any hints.
 
Andris Jekabsons
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should have googled more precisely, as the solution was not far away.
As explained here:
http://forum.java.sun.com/thread.jspa?threadID=300557&start=15&tstart=0
all I was missing was creating the driver instance:

Now I just have to look more into the Driver.getPropertyInfo() for more ways to gathering connection information for various kinds of drivers.
[ April 12, 2006: Message edited by: Andris Jekabsons ]
 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for posting the followup, I was curious...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic