Hello,
I spent now several hours searching the google groups without finding
an solution. I am kind of Newbie to DB2 and JSP and therefore working
with JSP4Dummies (not sure whether I should recommend this book):
Invoking the following jsp-file in the browser I get an
ClassNotFoundEx ception for the COM.ibm.db2.jdb c.app.DB2Driver .
JSP-File
*************** *************** *************** *************** *************** *****
<html>
<head>
</head>
<%@ page language="java" import="java.sq l.*" %>
<body>
<h1>Mitarbeit er-Liste</h1>
<%
try {
Class.forName(" COM.ibm.db2.jdb c.app.DB2Driver ");
System.out.prin tln(new java.util.Date( ).toString() + " DRIVER
FOUND.");
Connection db2Conn =
DriverManager.g etConnection("j dbc:db2:testdb" ,"db2admin","db 2admin");
Statement stmt = db2Conn.createS tatement();
String query ="select * from personal";
ResultSet myResultSet = stmt.executeQue ry(query);
if (myResultSet != null) {
while (myResultSet.ne xt()) {
String vorname = myResultSet.get String("vorname ");
String nachname = myResultSet.get String("nachnam e");
%>
<br>
<b><%= vorname%> <%= nachname%></b>
<br>
<%
}
}
stmt.close();
db2Conn.close() ;
}
catch(Exception e)
{
out.println(new java.util.Date( ).toString() + " Error 1:
"+e.getMessage( ));
}
%>
</body>
</html>
*************** *************** *************** *************** *************** *****
My Environment:
- DB2 v8.1.7
- j2sdk1.4.2_06
- Tomcat4.0.2
- OS: Windows XP Professional
To connect to the database I am using db2java.zip (C:\SQLLIB\java )
which I copied to C:\entwicklung\ Tomcat4.0.2\lib \ and to
C:\j2sdk1.4.2_0 6\jre\lib
Normally the ClassNotFoundEx ceptions has to do something with the
Classpath but I already included the db2java.zip into the
classpath:
CLASSPATH"...C: \entwicklung\To mcat4.0.2\webap ps\examples\WEB-INF\classes;C:\ entwicklung\Tom cat4.0.2\common \lib\servlet.ja r;C:\entwicklun g\Tomcat4.0.2\l ib\db2java.zip; C:\j2sdk1.4.2_0 6\jre\lib\db2ja va.zip;C:\sqlli b\java\db2java. zip"
Adding .newInstance() to the
Class.forName(" COM.ibm.db2.jdb c.app.DB2Driver ") is not making any
difference.
Surprisingly the following java file (doing pretty much the same) can
be compiled (javac) and executed (command prompt) without any problems
in the same environment.
JAVA-File
*************** *************** *************** *************** *************** *****
import java.sql.*;
public class TestQuery {
public TestQuery() {
}
public static void main(String args[]) {
String url="jdbc:db2:t estdb";
Connection con;
String query ="SELECT * FROM personal";
Statement stmt;
try{
Class.forName(" COM.ibm.db2.jdb c.app.DB2Driver ");
}
catch (java.lang.Clas sNotFoundExcept ion e) {
System.err.prin t("KlasseNichtG efundenAusnahme : ");
System.err.prin tln(e.getMessag e());
}
try {
System.out.prin tln("Versuche mich zu verbinden...");
con= DriverManager.g etConnection("j dbc:db2:testdb" ,"db2admin","db 2admin");
System.out.prin tln("Verbunden" );
stmt =con.createStat ement();
ResultSet result =stmt.executeQu ery(query);
while (result.next()) {
String name = result.getStrin g(1) +" "+
result.getStrin g(2);
System.out.prin tln(name);
}
stmt.close();
con.close();
}
catch(SQLExcept ion ex) {
System.err.prin t("SQLException :");
System.err.prin tln(ex.getMessa ge());
}
}
}
*************** *************** *************** *************** *************** *****
I would be happy to get any hints,
Andrea