Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help on dynamic loading of jdbc driver

 
Geronimo M. Hernandez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm trying to use a jdbc-driver in a quite dynamic way, which means, that at application start, neither the jarfile of the driver is part of the classpath, nor the classname of the driver is known.

The loading of the jar, the classpath extension and initializing of the driver works so far.
But when I try to use that driver, I get an SQL-Exception complaining that no usable driver can be found for the url.

So I added a LogWriter to the DriverManager and I got the message, that the DriverManager is skipping my loaded driver.
My code is this:



And the output is this:


The related code-snippet from DriverManager source-file is:


Can anybody give me a helping hand about what to do, to successfully load a jdbc-driver at runtime?

kind regards

Geronimo
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geronimo M. Hernandez wrote:The loading of the jar, the classpath extension and initializing of the driver works so far


Are you sure?



How do you load the jar?
 
Geronimo M. Hernandez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

thanks for your attention.

Are you sure?

If you look at the provided code snippets, you'll see, that the query of the DriverManager will be performed only if the creation of the Driver-instance was successful.

Meanwhile I got it and it works.
The DriverManager was the problem. I think, the so-called "security-question" (which I don't really understand) is anything else but security, so I wrote a replacement for the DriverManager and now the dynamic driver loading works as expected.

kind regards

Geronimo
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic