Why class not found? - Mailing list pgsql-jdbc

From Michael Hanna
Subject Why class not found?
Date
Msg-id 3575524A-B75B-11D6-A0A7-00039308EB2C@hwcn.org
Whole thread Raw
Responses Re: Why class not found?  ("Nick Fankhauser" <nickf@ontko.com>)
List pgsql-jdbc
OK, thanks to all regarding my previous Exceptions question.

New problem: I'm getting a ClassNotFoundException from this line:

        Class.forName("org.postgresql.Driver"); //load the driver

However I do import this package and I'm certain it's in my classpath:

[taoki:~] michael% $CLASSPATH
/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Classes/classes.
jar:/usr/local/jakarta-
tomcat-4.0.3/common/lib/servlet.jar:/usr/local/pgsql/share/java/pgjdbc2.jar:
./: Command not found.
[taoki:~] michael%

Also that HelloPostgresql.class by Mr. Fankhauser works fine..

Any ideas...

here's the whole code:

--

Rigby.java

--

// Copyright Michael Hanna 2002
// do not use without permission of author

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;   // All we need for JDBC

public class Rigby extends HttpServlet {

     public void doGet(HttpServletRequest request, HttpServletResponse
response)throws IOException, ServletException
{
     PrintWriter out;
     DBThing dbt;
     ResultSet results;

    String database = "rigby";
    String username = "postgres";
    String password = "postgres";

    response.setContentType("text/html");
    out = response.getWriter();
    out.println("<html>");
    out.println("<body>");
    out.println("<head>");
    out.println("<title>Rigby</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Contents of friends:</h1>");

    try {
        Class.forName("org.postgresql.Driver"); //load the driver
        out.println("<B>Inside try</B>");
        dbt = new DBThing(database, username, password);
        results = dbt.queryDB("select * from friends");

        if (results != null)
        {
        out.println("<B>id" + "First Name" +"Surname" + "Email" +
"Phone"+"Bday</B>");
        while (results.next())
        {
            out.println(results.getInt("id") +
results.getString("firstname") + results.getString("surname")+
results.getString("email")+results.getInt("tel")+results.getString("date") +
"\n");
        }
        }
        else {
        out.println("The friends database is empty.<br>");
        }
        results.close();

    } catch (ClassNotFoundException cnf) {
        out.println("***Exception:\n"+cnf);
        cnf.printStackTrace();
    } catch (SQLException se) {
        out.println("***Exception:\n"+se);
        se.printStackTrace();
    }
    out.println("hey2");
    out.println("</body>");
    out.println("</html>");


    /*
     try {
         new DBThing(database, user, password);
     } catch (ClassNotFoundException cnfe) {
         throw new IOException("Could not instantiate driver: " +
cnfe.getMessage());
     } catch (SQLException se) {
         throw new IOException("Unable to connect to database or work
with it: " + se.getMessage());
     }
     */

}
}

--

DBThing.java


--

// Copyright Michael Hanna 2002
// do not use without permission of author

import java.sql.*;   // All we need for JDBC
import java.lang.*;

public class DBThing
{
     Connection       db;        // A connection to the database
     Statement        sql;       // Our statement to run queries with
     DatabaseMetaData dbmd;      // This is basically info the driver
delivers
                // about the DB it just connected to. I use
     // it to get the DB version to confirm the
     // connection in this example.

     public DBThing(String database, String username, String password)
    throws ClassNotFoundException, SQLException
     {

    Class.forName("org.postgresql.Driver"); //load the driver

    db = DriverManager.getConnection("jdbc:postgresql:"+database,
                  username,
                  password); //connect to the db

    dbmd = db.getMetaData(); //get MetaData to confirm connection
    System.out.println("Connection to "+dbmd.getDatabaseProductName()+" "+
                        dbmd.getDatabaseProductVersion()+"
successful.\n");

    sql = db.createStatement(); //create a statement that we can use later

     }

     public ResultSet queryDB(String query) throws SQLException
     {
    ResultSet rs;
    rs = sql.executeQuery(query); // try to query DB
    return rs;
     }
}


pgsql-jdbc by date:

Previous
From: Barry Lind
Date:
Subject: Re: Authentication Problems
Next
From: "Nick Fankhauser"
Date:
Subject: Re: Why class not found?