Article View: borland.public.jbuilder.java.language
Article #168Re: changing class path at run time
From: Paul Furbacher [TeamB]
Date: Thu, 30 Mar 2006 03:34
Date: Thu, 30 Mar 2006 03:34
62 lines
3010 bytes
3010 bytes
Try this:
public void getConnection(
String classname,
String filename,
String dbUrl,
Properties props) {
try {
File f = new File(filename);
URL[] urlList = new URL[] { f.toURL() };
URLClassLoader cld =
new URLClassLoader(
urlList,
this.getClass().getClassLoader());
Driver driver =
(Driver)cld.loadClass(classname).newInstance();
Connection connection = driver.connect(dbUrl, props);
/* instead of
Connection connection =
DriverManager.getConnection(dbUrl, props);
*/
}
catch (Exception ex) {
ex.printStackTrace();
}
}
What I missed was the fact that you have to use
the driver instance itself in this scenario, not
the DriverManager whose class loader will never
know about the dynamically loaded class ... at least
I think that's the explanation. [Feel free to correct
me if I'm wrong.]
[Thanks to the Cayenne contributors, Andrei Adamchik in particular,
for this solution. If you want to see it yourself, see the class,
org.objectstyle.cayenne.conn.DriverDataSource. It's unfortunate
that Cayenne is not more widely known -- my gut feeling is that
it's a heck of a lot smoother an experience than Hibernate, which
to me is very quirky. Cayenne has just admitted as a Jakarta
Incubator project.
http://incubator.apache.org/projects/cayenne.html
I'm hoping that will boost its prominence.]
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://info.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Technical Details
Message-ID:
<442b51bb$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<442953d2$1@newsgroups.borland.com> <44296071$1@newsgroups.borland.com> <4429630f@newsgroups.borland.com> <4429a3e5@newsgroups.borland.com> <4429e83e$1@newsgroups.borland.com> <442afca7$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,93e0a6dd5feccd47 X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Wed, 29 Mar 2006 22:34:14 -0500 From: "Paul Furbacher [TeamB]" <pfurbacher@mac.com> Organization: Reverse Alchemy, Inc. User-Agent: Thunderbird 1.5 (Macintosh/20051201) MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: changing class path at run time References: <442953d2$1@newsgroups.borland.com> <44296071$1@newsgroups.borland.com> <4429630f@newsgroups.borland.com> <4429a3e5@newsgroups.borland.com> <4429e83e$1@newsgroups.borland.com> <442afca7$1@newsgroups.borland.com> In-Reply-To: <442afca7$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 69.142.194.228 Message-ID: <442b51bb$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1143689659 69.142.194.228 (29 Mar 2006 19:34:19 -0700) Lines: 62 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail