Re: [tcljava-user] Class not found after successful class import.]
Brought to you by:
mdejong
From: Patrick F. <pfi...@oz...> - 2005-11-21 12:57:12
|
Thanks for the tip Mo. The class is loaded but I now get an SQL error. "set c [ java::field ClientDriver class ]" This loads the class but the subsequent call to "DriverManager" generates a "no suitable driver sql error". I am trying to emulate the JDBC load database driver using the Class forName technique explained here: http://www.jguru.com/faq/view.jsp?EID=11164 Class.forName("org.apache.derby.jdbc.EmbeddedDriver"); Connection conn = DriverManager.getConnection( "jdbc:derby:mynewDB", p); In JACL the method call fails with a class not found error. "java::call Class forName org.apache.derby.jdbc.ClientDriver" "set ConnectionI [ java::call DriverManager getConnection $url ]" I had another look at the Class API and added the tcl class loader as the loader parameter. set c [ java::field ClientDriver class ] set classLoader [ $c getClassLoader ] In this case the classloader is " tcl.lang.TclClassLoader" because the jar file containing "ClientDriver" is specified using the tcl_classpath variable. "java::call Class forName org.apache.derby.jdbc.ClientDriver true $classLoader" Class.forName now loads ClientDriver but I still get "java.sql.SQLException: No suitable driver" on the call to DriveManager. It does look like a classloader issue. The work around is to add the Derby database jar files to the system classpath. set CLASSPATH=%CLASSPATH%;C:\IBM\Cloudscape_10.1\lib\derby.jar set CLASSPATH=%CLASSPATH%;C:\IBM\Cloudscape_10.1\lib\derbyclient.jar set CLASSPATH=%CLASSPATH%;C:\IBM\Cloudscape_10.1\lib\derbynet.jar set CLASSPATH=%CLASSPATH%;C:\IBM\Cloudscape_10.1\lib\derbytools.jar c:\tclblendSun\bin\jtclsh.bat C:\CvsSandbox\FITZROY\FM\SCRIPTS\TCL\JACL\cloudscape\createCloudScapeDB.tcl When the foloowng statements are executed................... set c [ java::field ClientDriver class ] set classLoader [ $c getClassLoader ] the classloader for ClientDriver is now "sun.misc.Launcher$AppClassLoader" and the call to DriveManager succeeds. So it would seem that the process that the database driver class uses to register the driver with the DriveManager only works if it's loaded with the same class loader as the DriveManager. "The specified driver must implement the Driver interface. A class initializer (static code block) within the OracleDriver class registers the driver with the DriverManager". Regards. Patrick. |