By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,885 Members | 1,072 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,885 IT Pros & Developers. It's quick & easy.

jsp - jdbc connection to db2v8 failing

P: n/a
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
ClassNotFoundException for the COM.ibm.db2.jdbc.app.DB2Driver.

JSP-File
************************************************** ******************************
<html>
<head>
</head>
<%@ page language="java" import="java.sql.*" %>
<body>
<h1>Mitarbeiter-Liste</h1>
<%
try {
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
System.out.println(new java.util.Date().toString() + " DRIVER
FOUND.");
Connection db2Conn =
DriverManager.getConnection("jdbc:db2:testdb","db2 admin","db2admin");
Statement stmt = db2Conn.createStatement();
String query ="select * from personal";
ResultSet myResultSet = stmt.executeQuery(query);
if (myResultSet != null) {
while (myResultSet.next()) {
String vorname = myResultSet.getString("vorname");
String nachname = myResultSet.getString("nachname");
%>
<br>
<b><%= vorname%>&nbsp;&nbsp;<%= 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_06\jre\lib

Normally the ClassNotFoundExceptions has to do something with the
Classpath but I already included the db2java.zip into the

classpath:

CLASSPATH"...C:\entwicklung\Tomcat4.0.2\webapps\ex amples\WEB-INF\classes;C:\entwicklung\Tomcat4.0.2\common\lib\ servlet.jar;C:\entwicklung\Tomcat4.0.2\lib\db2java .zip;C:\j2sdk1.4.2_06\jre\lib\db2java.zip;C:\sqlli b\java\db2java.zip"

Adding .newInstance() to the
Class.forName("COM.ibm.db2.jdbc.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:testdb";
Connection con;
String query ="SELECT * FROM personal";
Statement stmt;
try{
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
}
catch (java.lang.ClassNotFoundException e) {
System.err.print("KlasseNichtGefundenAusnahme: ");
System.err.println(e.getMessage());
}
try {
System.out.println("Versuche mich zu verbinden...");
con= DriverManager.getConnection("jdbc:db2:testdb","db2 admin","db2admin");
System.out.println("Verbunden");
stmt =con.createStatement();
ResultSet result =stmt.executeQuery(query);
while (result.next()) {
String name = result.getString(1) +" "+
result.getString(2);
System.out.println(name);
}
stmt.close();
con.close();
}
catch(SQLException ex) {
System.err.print("SQLException:");
System.err.println(ex.getMessage());
}

}
}

************************************************** ******************************

I would be happy to get any hints,

Andrea
Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Andrea wrote:
Invoking the following jsp-file in the browser I get an
ClassNotFoundException for the COM.ibm.db2.jdbc.app.DB2Driver.

[...]

Are you sure Tomcat uses this classpath? If started as a service, it's
quite probable that it uses a different one.

Try converting the db2java.zip to a jar (Tomcat 5 requires libraries to
be .jar files, not .zip) and putting it into
C:\entwicklung\Tomcat4.0.2\common\lib (restart Tomcat afterwards, obviously)

hth,
Benjamin
--
Please compose your messages as plaintext:
http://www.netby.dk/Oest/Europa-Alle/vermeer/plain.html
And do not send MS Office attachments:
http://www.goldmark.org/netrants/no-word/attach.html
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.