jsp - jdbc connection to db2v8 failing
From: Andrea (Drea_79_at_web.de)
Date: 01/13/05
- Previous message: yasaswi: "plsql vs hibernate"
- Next in thread: Benjamin Gufler: "Re: jsp - jdbc connection to db2v8 failing"
- Reply: Benjamin Gufler: "Re: jsp - jdbc connection to db2v8 failing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 13 Jan 2005 05:56:00 -0800
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","db2admin","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%> <%= 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\examples\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:\sqllib\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","db2admin","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
- Previous message: yasaswi: "plsql vs hibernate"
- Next in thread: Benjamin Gufler: "Re: jsp - jdbc connection to db2v8 failing"
- Reply: Benjamin Gufler: "Re: jsp - jdbc connection to db2v8 failing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|