title: java.lang.ClassNotFoundException: org.postgresql.Driver postgresql ubuntu
body: <p>I have configured apache tomcat in ubuntu. I am using postgresql as database. I have downloaded <code>postgresql-9.3-1101.jdbc3.jar</code> connector and set <code>CLASSPATH</code> as follows:</p>
  
  <pre><code>export CLASSPATH=/var/lib/tomcat7/webapps/CMAS/WEB_INF/lib/postgresql-9.3-1101.jdbc3.jar
  </code></pre>
  
  <p>I am using a JSP program to access Database values, code as follows:</p>
  
  <pre><code>&lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.* " %&gt;
  &lt;%@ page import="java.io.*" %&gt;
  &lt;%
  try {
  String driver = "org.postgresql.Driver";
  String url = "jdbc:postgresql://localhost:5432/CMAS";
  String username = "postgres";
  String password = "postgres";
  
  String myDataField = null;
  String myQuery = "SELECT * FROM survey_details";
  Connection myConnection = null;
  PreparedStatement myPreparedStatement = null;
  ResultSet myResultSet = null;
  Class.forName(driver).newInstance();
  myConnection = DriverManager.getConnection(url,username,password);
  myPreparedStatement = myConnection.prepareStatement(myQuery);
  myResultSet = myPreparedStatement.executeQuery();
  if(myResultSet.next()){
  out.print("herezz");
  myDataField = myResultSet.getString("imei");
  out.print(myDataField);
  }
  }
  catch(Exception e){
  out.print(e);
  }
  
  %&gt;
  </code></pre>
  
  <p>I am getting an exception "java.lang.ClassNotFoundException: org.postgresql.Driver". I understand its because of classpath. But how can I fix this?</p>