Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: Dynamic cla...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 11 Topic 16056 of 16078
Post > Topic >>

Re: Dynamic classpath

by Thomas Kellerer <YQDHXVLMUBXG@[EMAIL PROTECTED] > May 7, 2008 at 02:17 PM

Sorry, I meant Driver.connect()

Once you have loaded the driver class using a URLClassLoader, you can
create a new instance and cast that to a Driver and then ask the driver to
connect.

Something like this:

URLClassLoader l = new URLClassLoader(...);
Class drvClass = l.loadClass("org.postgresql.Driver");
java.sql.Driver drv = (java.sql.Driver)drvClass.newInstance();
Properties props = new Properties();
props.put("user", "postgres");
props.put("password", "password");

java.sql.Connection conn = drv.connect("jdbc:postgresql:localhost/mydb",
props);

Regards
Thomas



wizard of oz, 07.05.2008 13:38:
> Can you post an example of Connection.connect (String, properties)?
> 
> My java doc says java.sql.Connection is an interface and doesn't mention
a
> connect method.
> 
> TIA
> 
> "Thomas Kellerer" <YQDHXVLMUBXG@[EMAIL PROTECTED]
> wrote in message 
> news:68d9soF2r6qjbU1@[EMAIL PROTECTED]
>> wizard of oz, 07.05.2008 10:41:
>>> I have a need to have a classpath that is determined by the set of 
>>> jars a user places into a directory.
>>>
>>> By way of example, placing jar's into certain directories in a tomcat 
>>> web server will cause tomcat to include them into the web 
>>> applications class path. An example of this might be a charting 
>>> package used by the web app to generate charts.
>>>
>>> In my specific example, I am building a query tool and I want to be 
>>> able to tell users to simply drop the JDBC drivers into a directory 
>>> and my app will "pick them up". Thus there would be no need to edit 
>>> the classpath.
>>>
>>> My target environment is Java 6.0
>>>
>>
>> You will need to use a URLClassLoader to load the driver(s)
>> The only problem is then doing the connection as the DriverManager 
>> will refuse to use a driver that was loaded by a different classloader.
>>
>> You have two options to resolve this:
>>
>> 1) use Connection.connect(String, Properties) directly (bypassing 
>> DriverManager) 2) create a wrapper class that pretends to be a driver 
>> but delegates everything to the real instance (loaded by your own 
>> classloader).
>> I am using option 1) without any problems.
>>
>> Thomas
>>
>




 11 Posts in Topic:
Dynamic classpath
"wizard of oz"   2008-05-07 08:41:27 
Re: Dynamic classpath
Thomas Kellerer <YQDHX  2008-05-07 11:08:40 
Re: Dynamic classpath
"wizard of oz"   2008-05-07 11:38:28 
Re: Dynamic classpath
Thomas Kellerer <YQDHX  2008-05-07 14:17:17 
Re: Dynamic classpath
"wizard of oz"   2008-05-08 01:26:56 
Re: Dynamic classpath
Lew <lew@[EMAIL PROTEC  2008-05-07 21:38:01 
Re: Dynamic classpath
"wizard of oz"   2008-05-08 05:15:00 
Re: Dynamic classpath
Roedy Green <see_websi  2008-05-07 13:51:08 
Re: Dynamic classpath
Ian Shef <invalid@[EMA  2008-05-15 18:51:18 
Re: Dynamic classpath
"John B. Matthews&qu  2008-05-15 20:01:43 
Re: Dynamic classpath
Casper Bang <casper@[E  2008-05-08 21:37:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 23:39:54 CDT 2008.