简体   繁体   中英

Loading a class at runtime

I have some code which loads the class at runtime:

Class.forName("oracle.jdbc.driver.OracleDriver");

But there seems to be issues with this and IKVM - I was wondering if there were any alternative ways to achieve the above in my Java program or if anyone knew on why that might cause issued with ikvm?

Thanks

sorry - i didnt no how to find out, its taken me ages to get this far! This is caught in the Exception e catch statement and i am pretty sure its thrown by the line posted above

classname IKVM.NativeCode.java.lang.Class Filename null Method name forName0 Line number -1 classname java.lang.Class Filename Class.java Method name forName0 Line number -2 classname java.lang.Class Filename Class.java Method name forName Line number 287 classname Test Filename Test.java Method name init Line number 50 classname Test Filename Test.java Method name isPDFAvailable Line number 24 classname cli.Analytical_Report.Form1 Filename Form1.cs Method name hasGains Line number 296 classname cli.Analytical_Report.Form1 Filename Form1.cs Method name determineAvailableData Line number 209 classname cli.Analytical_Report.Form1 Filename Form1.cs Method name consumeFile Line number 71 classname cli.Analytical_Report.Form1 Filename Form1.cs Method name btnSelectFile_Click Line number 49 classname cli.System.Windows.Forms.Control Filename null Method name OnClick Line number -1 classname cli.System.Windows.Forms.Button Filename null Method name OnClick Line number -1 classname cli.System. Windows.Forms.Button Filename null Method name OnMouseUp Line number -1 classname cli.System.Windows.Forms.Control Filename null Method name WmMouseUp Line number -1 classname cli.System.Windows.Forms.Control Filename null Method name WndProc Line number -1 classname cli.System.Windows.Forms.ButtonBase Filename null Method name WndProc Line number -1 classname cli.System.Windows.Forms.Button Filename null Method name WndProc Line number -1 classname cli.System.Windows.Forms.Control$ControlNativeWindow Filename null Method name OnMessage Line number -1 classname cli.System.Windows.Forms.Control$ControlNativeWindow Filename null Method name WndProc Line number -1 classname cli.System.Windows.Forms.NativeWindow Filename null Method name DebuggableCallback Line number -1 classname cli.System.Windows.Forms.UnsafeNativeMethods Filename null Method name DispatchMessageW Line number -1 classname cli.System.Windows.Forms.Application$ComponentManager Filename null Method name System.Windows.Form s.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop Line number -1 classname cli.System.Windows.Forms.Application$ThreadContext Filename null Method name RunMessageLoopInner Line number -1 classname cli.System.Windows.Forms.Application$ThreadContext Filename null Method name RunMessageLoop Line number -1 classname cli.System.Windows.Forms.Application Filename null Method name Run Line number -1 classname cli.Analytical_Report.Program Filename Program.cs Method name Main Line number 18 classname cli.System.AppDomain Filename null Method name _nExecuteAssembly Line number -1 classname cli.System.AppDomain Filename null Method name ExecuteAssembly Line number -1 classname cli.Microsoft.VisualStudio.HostingProcess.HostProc Filename null Method name RunUsersAssembly Line number -1

Different database format and JDBC driver, but it will work for you with slight modification for oracle and oracle driver (full Namespaces for clarity purposes):

java.lang.Class.forName(typeof(org.hsqldb.jdbcDriver).AssemblyQualifiedName);
java.sql.DriverManager.registerDriver(new org.hsqldb.jdbcDriver());
conn = java.sql.DriverManager.getConnection(url, username, password);

It's the first time I hear about ikvm, but I will try to help.

First, another way to load the JDBC driver is with

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Anyhow, I have read in the ikvm website that you have to convert your JARs to DLLs using the command ikvmc. Did you already convert the Oracle driver JAR to a DLL? And:are you sure you have make the classes in this JAR/DLL available to the program? (Whatever equivalent there is for the Java classpath)

Hope that helps!

您可以在IKVM wiki中查看ClassLoader或更好地描述您的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM