jsp - jdbc connection to db2v8 failing - JDBC JAVA

This is a discussion on jsp - jdbc connection to db2v8 failing - JDBC JAVA ; 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 ...

+ Reply to Thread
Results 1 to 2 of 2

jsp - jdbc connection to db2v8 failing

  1. Default jsp - jdbc connection to db2v8 failing

    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%>&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\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

  2. Default Re: jsp - jdbc connection to db2v8 failing

    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

+ Reply to Thread

Similar Threads

  1. Data Source connection failing
    By Application Development in forum ODBC
    Replies: 1
    Last Post: 11-08-2007, 10:54 AM
  2. Re: problem with JDBC connection
    By Application Development in forum Java
    Replies: 0
    Last Post: 06-29-2007, 05:48 AM
  3. sendmail is failing with I/O connection errors
    By Application Development in forum SendMail
    Replies: 4
    Last Post: 05-21-2007, 05:50 AM
  4. Re: JDBC connection for DBF files
    By Application Development in forum ADO DAO RDO RDS
    Replies: 0
    Last Post: 01-04-2007, 11:50 AM
  5. Single JDBC connection for EJB CMP?
    By Application Development in forum Java
    Replies: 1
    Last Post: 03-01-2004, 04:00 PM