A ClassNotFoundException
simply means that the in the message mentioned class is missing in the runtime classpath. Just add the JDBC driver JAR file to the runtime classpath of the beanshell script. Here's an extract of the documentation:
addClassPath( URL | path )
Add the specified directory or archive to the classpath. Archives may be located by URL, allowing them to be loaded over the network.
Examples:
addClassPath( "/home/pat/java/classes" );
addClassPath( "/home/pat/java/mystuff.jar" );
addClassPath( new URL("http://myserver/~pat/somebeans.jar") );
Then, to load the driver class, you need to use Beanshell's provided getClass()
method instead of the standard Class#forName()
. Here's an extract of the documentation:
In order to perform an explicit class lookup by name while taking into account any BeanShell class path modification you must use a replacement for the standard Class.forName()
method.
The getClass()
command will load a class by name, using the BeanShell classpath. Alternately, you can consult the class manager explicitly:
name="foo.bar.MyClass";
c = getClass( name );
c = BshClassManager.classForName( name ); // equivalent