I don't know if you've solved this yet but if you haven't, I may have good news. I was
having the same problem the other day - which is why I saved your post - and finally
figured it out.
I'm using JBuilder6 to develop a servlet in their Tomcat 3.2 test environment. I was
having the exact same problem with the servlet not seeing my JDBC driver despite
having put the driver path everywhere.
I finally solved the problem by:
- going to Project/Project Properties in JBuilder6
- clicking on the WebServer tab
- ensuring that Tomcat 3.2 was selected
- clicking on the Setup button beside the dropdown box that says "Tomcat 3.2"
- clicking on the Required Libraries tab
- adding the library that contained my driver file (in my case, the driver file was in
C:\Program Files\SQLLIB\java\db2java.zip). This puts the JDBC driver library second in
the list, under "Tomcat 3.2 Servlet".
- ***selecting my JDBC driver library and clicking the "Move Up" button.*** [That was
the critical step; previously, I had the JDBC driver library BELOW the Tomcat 3.2
Servlet library and it wouldn't work.]
- clicking OK until I was back in my development environment. On the very first test
after that, the servlet saw my JDBC driver just fine.
I hope you can translate those instructions into something meaningful for your
development environment :-)
Rhino
>>> [EMAIL PROTECTED] 07/10/02 02:41PM >>>
Hi,
I have a simple servlet which which registers a DB2 jdbc driver, and
attempts to
retrieve information for a sample table I created.
I'm running this on Tomcat 4.0. I'm using IBM's DB2 UDB v 7.x. The
archive
containing the DB2 jdbc driver is : "db2java.zip".
I've utilized the same driver-related code in applets and applications
(both net
and app based drivers) without any problem.
However, when I use the code in the servlet, the class loader cannot
locate
the driver, ergo, cannot locate the archive. Here's the exact message...
====================================================
java.lang.ClassNotFoundException: COM.ibm.db2.jdbc.net.DB2Driver
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa
der.java:1307)
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoa
der.java:1156)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:322)
====================================================
I've "blanketed" Tomcat's directories with my "db2java.ip" file (based
on Tomcat's
documentation re: Class Loader Info.)
However, I have NOT ammended the web.xml file in my WEB-INF directory
specific
to my servlet.
How do I resolve this problem? (it's extremely frustrating, since it appears
to be a configuration
issue only!)
Thank you in advance.
John
PS. The code is listed below.
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import java.sql.*;
import javax.servlet.http.*;
import COM.ibm.db2.jdbc.net.DB2Driver.*;
public class cmdtest extends HttpServlet {
Connection con;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
String title = rb.getString("cmdtest.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out.println("<body>");
out.println("<a href=\"/examples/servlets/cmdtest.html.html\">");
out.println("<img src=\"/examples/images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
out.println("<a href=\"/examples/servlets/index.html\">");
out.println("<img src=\"/examples/images/return.gif\" height=24 " +
"width=24 align=right border=0 alt=\"return\"></a>");
out.println("<h1>" + title + "</h1>");
try {
// register the driver with DriverManager
// The newInstance() call is needed for the sample to work with
// JDK 1.1.1 on OS/2, where the Class.forName() method does not
// run the static initializer. For other JDKs, the newInstance
// call can be omitted.
Class.forName("COM.ibm.db2.jdbc.net.DB2Driver").newInstance();
} catch (Exception e) {
e.printStackTrace();
}
try {
// construct the URL ( sample is the database name )
String url = "jdbc:db2://localhost:6789/CMD_PROD";
String userid = "itd";
String password = "cmdit!0801";
// connect to database with userid and password
con = DriverManager.getConnection(url, userid, password );
out.println("<h1>" + connectMsg2 + "</h1>");
} catch( Exception e ) {
e.printStackTrace();
}
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from CMD_COMPANY");
// display the result set
// rs.next() returns false when there are no more rows
int y = 50;
int i = 0;
while (rs.next() && (i<10)) {
i++;
String a= rs.getString(2);
String str = rs.getString(3);
String oneLine = " Comp. Name= " + a + " Comp. Abbr.= " +
str;
file://g.drawString(oneLine, 20, y );
out.println("<h1>" + oneLine + "</h1>");
y = y + 15;
}
stmt.close();
} catch( Exception e ) {
e.printStackTrace();
}
out.println("</body>");
out.println("</html>");
}
}
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html