Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

loading JDBC driver from a Jar (not in classpath)

 
Andris Jekabsons
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting the followup, I was curious...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic