Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PostgreSQL & JDBC - ClassNotFoundException

843859Mar 31 2006 — edited Apr 8 2009
I'm trying to get my servlet to play nicely with postgresql, but I keep getting a ClassNotFoundException at compile time. I have added only one line (Class.forName("org.postgresql.Driver");) to a previously working servlet - it should initialize the driver as per the postgresql documentation, but it keeps throwing this error.

I recognize that this should have to do with the classpath, but I've tried many different configurations and it's still broken. $CLASSPATH currently looks like this:
:/usr/local/tomcat/webapps/test/WEB-INF/servlet-api.jar:/usr/local/tomcat/webapps/test/WEB-INF/postgresql-8.1-405.jdbc3.jar:/usr/local/tomcat/webapps/test/WEB-INF/classes/
i looked into that postgresql-8.1-405.jdbc3.jar file, and the org.postgresql.Driver is present. running simply "java org.postgresql.Driver" successfully finds the class. I've tried setting the classpath at the command line when running javac too, and i still get the same error. I'm out of ideas!

Below is (the relevant part of) my code. Any help is most appreciated!
package mypackage;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;

public final class Map extends HttpServlet { 

   List<Location> aList = new ArrayList<Location>(2);
   Location a = new Location("Apartment #1","Residence"," West 4th St", -74.001634, 40.732889);
   Location b = new Location("Apartment #2","Residence","Bank St", -74.003161, 40.737430);
   
   public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
      throws IOException, ServletException {

         aList.add(0, a);
         aList.add(1, b);

	Class.forName("org.postgresql.Driver");

	response.setContentType("text/html");


	PrintWriter writer = response.getWriter();

	writer.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"");

//And it goes on for a while like that, then ends with...

	}


}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 6 2009
Added on Mar 31 2006
7 comments
778 views