Classpath Frustrations

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Classpath Frustrations

Michael Freeman
Why does the following beanhshell script generate a
"No suitable driver" exception when trying to obtain a
JDBC connection?

==================================================
String path = "c:/javalibs/jtds_1.2/jtds-1.2.jar";
File f = new File(path);

ClassLoader ccl =
Thread.currentThread().getContextClassLoader();
urls = new URL[] {f.toURL()};
ClassLoader urlc = new URLClassLoader(urls,ccl);
Thread.currentThread().setContextClassLoader(urlc);

String driver = "net.sourceforge.jtds.jdbc.Driver";
String url = "jdbc:jtds:sqlserver://localhost/mydb";

this.interpreter.setClassLoader(urlc);

Class clazz = getClass(driver);
clazz.newInstance();

import java.sql.*;

Connection c =
DriverManager.getConnection(url,"sa","password");
c.close();
===============================================

Since JDBC (as i understand it) uses the thread
context classloader and (i thought) i pointed
BeanShell to using that same class loader i would have
thought everyone would have been happy (the
class.newInstance works OK as expected for example)

I know i could put the JDBC driver in the -cp
classpath when i invoke BeanShell but for a variety of
reasons i need to make this run time discovery of JARs
technique work...

Can someone tell me what i am missing here?

thanks

--Mike



 
____________________________________________________________________________________
Want to start your own business?
Learn how on Yahoo! Small Business.
http://smallbusiness.yahoo.com/r-index

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users