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
archivecontaining 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