|
Java Apache Project : Apache JServ 1.0 : Programming and Misc. Tidbits :
Why do I get a ClassNotFoundException on my JDBC driver? |
I'm not sure who to send this too, but I've read much
documentation and I can't figure out why I can't get a jdbc
driver or two to work in my servlets
The first few lines of service
are
public void service (
HttpServletRequest request,
HttpServletResponse response
) throws ServletException, IOException
{
PrintWriter out;
String title = "Simple Servlet Output";
String dead = "default";
try {
Class.forName("org.gjt.mm.mysql.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://db.domain.com:3306/AMR?user=root&password=");
System.out.println("Connected to the db");
dead = "but I'm not dead yet";
}
catch (ClassNotFoundException e) {
System.out.println("Couldn't find class: " +
e.getMessage());
dead = "died- ClassNotFoundException";
}
catch (SQLException se){
System.out.println("SQL Exception caught: " + se);
dead = "died- SQLException";
}
If I print dead it is always "died-ClassNotFoundException,
yet if I
do
import org.gjt.mm.mysql.Driver
and verbose on compile I get this:
why won't forName find it?
[loaded
c:\java\mm.mysql.jdbc-1.2a\mysql.jar(org/gjt/mm/mysql/Driver.class) in 94
ms]cmcclanahanATmytownnetDOTcom |
Your compile works because you have correctly added the MySQL driver's
JAR file to your system CLASSPATH. However, Apache JServ does not use this
CLASSPATH when it starts up. You must define the class path you want in the
configuration files. There are two places you can do this (the first one is
the better choice for a database driver):
(a) SYSTEM CLASSPATH
In the "jserv.properties" file, you can add entries like this to add things
to the system CLASSPATH that is used by Apache JServ and the servlets you run:
wrapper.classpath=/java/mm.mysql.jdbc-1.2a/mysql.jar
This will cause the driver to get loaded from the system class path, just like
it does for the compiler. However, any classes loaded from here cannot be
reloaded if you recompile them.
(b) ZONE CLASSPATH
If you want to take advantage of the automatic reloading feature (good for
servlets, but not really useful in the particular case of a JDBC driver), add
a line like this to your "zone.properties" file:
repositories=/my/path/to/myservlets
and the servlets in the "myservlets" directory will be reloaded when you change
them (assuming you have configured the autoreload feature on -- see the
configuration file documentation).
cmcclanahanATmytownnetDOTcom |
On Unix, set the LD_LIBRARY_PATH to your dynamic (ie: .so) files correctly.
On NT, set the java.library.path System property variable to the .dll files correctly. |
I have installed successfully Apache 1.3.9 and JServ 1.0.
I am using:
- Apache 1.3.9 on SunOS 5.7
- JServ 1.0
- Oracle JDBC-thin driver V8.1.6
I have tried many things but I always get:
[24/09/1999 15:11:36:545] (ERROR) ajp11: Servlet Error: Initialization error whi
le loading the servlet: ClassNotFoundException: oracle.jdbc.driver.OracleDriver!!
I have tried setting in jserv.properties :
wrapper.classpath=/opt/app/oracle/product/8.1.6/jdbc/lib/nlscharset12.zip
wrapper.classpath=/opt/app/oracle/product/8.1.6/jdbc/lib/classes12.zip
I have tried setting CLASSPATH.
I have tried creating a zone which points on my classes. Nothing worked! :(
I know that my servlet is working, I made it work with JSDK. jean_tremblayATdialogDOTcom |
Can anyone help me? jean_tremblayATdialogDOTcom |
Actually, none of the suggestions on this page solved my problem.
This one,
however, did.
acruiseATglobalmediaDOTcom |
| [Append to This Answer] |