Class.forName() with dynamic String
I'm trying to create objects of a class whose name depends on a runtime database lookup. So my code looks like this:
package com.mycompany.ourproduct.ourpackage;
. . .
String className = rs.getString(1);
Class c = Class.forName(className);
. . .
When I run the program, I get a ClassNotFoundException. But everything runs fine if I replace the code above with this:
package com.mycompany.ourproduct.ourpackage;
. . .
// String className = rs.getString(1);
String className = "com.mycompany.ourproduct.ourpackage.oursubpackage.MyClass"
Class c = Class.forName(className);
. . .
The problem seems to be in the dynamic linking. Although the class I'm trying to load is in a different package, it is a public class (and I can load it with a static string). Neither does moving it to the same package fix the problem.
I've noticed that if I supply a mis-named class with a static string, the exception reads:
java.lang.ClassNotFoundException: com.mycompany.ourproduct.misspelledpackage.SomeClass
but the same exception prints as follows when the string comes from the database:
java.lang.ClassNotFoundException: com/mycompany/ourproduct/misspelledpackage/SomeClass
I thought the difference was one of compile-time linking and run-time linking, but oddly enough, I still get the dots for misspelled classes that I (1) supply on the command line, (2) read from a file, or (3) concatenate from command line arguments plus info from a file. It's just when I pull the class name from the database that I get the slashes. Does anyone know what's going on?
Here's what I get from java -version:
java version "1.2.2"
Solaris VM (build Solaris_JDK_1.2.2_05a, native threads, sunwjit)
Any help would be greatly appreicated!

