title: No Suitable Driver found Postgres JDBC
body: <p>I am receiving a "no suitable driver found" error when I test my web service on tomcat. I have the JDBC .jar in the lib folder as various tutorials says to do. Here is my code:</p>
  
  <pre><code>public class PostDBConnection {
  
   PreparedStatement st;
   ResultSet rs;
   Connection con;
   DataSource ds;
   InitialContext cxt;
  
   String url = "jdbc:postgresql://127.0.0.1:5432/UptonDB";
   String user = "*****";
   String password = "*******";
   String query = "";
   StringBuilder response = new StringBuilder();
  
  @SuppressWarnings("unused")
  public String getInfo(){
  
      int size = 0;  
  
  
      try {
  
          cxt = new InitialContext();     
          ds = (DataSource) cxt.lookup("java:comp/env/jdbc/UptonDB");
  
      } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      try{
  
          try {
  
              Class.forName("org.postgres.Driver");
  
  
          } catch (ClassNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          con = DriverManager.getConnection(url, user, password);
          st =  con.prepareStatement("SELECT VERSION()");         
          rs = st.executeQuery();
  
  
          while(rs.next())
              {
                      response.append(rs.getString(1));
  
              }               
          }     
  
      catch(SQLException exc)
          {
              Logger lgr = Logger.getLogger(PostDBConnection.class.getName());
              lgr.log(Level.SEVERE, exc.getMessage(), exc);
          } 
      finally {
          try {
             if (rs != null) {
                  rs.close();
              }
              if (st != null) {
                  st.close();
              }
              if (con != null) {
                  con.close();
              }
  
          } catch (SQLException ex) {
              Logger lgr = Logger.getLogger(PostDBConnection.class.getName());
              lgr.log(Level.WARNING, ex.getMessage(), ex);
          }
      }
  
      return response.toString();
  }
  </code></pre>
  
  <p>Also here are the web.xml and context.xml files I created by following instructions on the Tomcat website:</p>
  
  <pre><code> &lt;resource-ref&gt;
  &lt;description&gt;PostgreSQL Data Source &lt;/description&gt;
  &lt;res-ref-name&gt;jdbc/UptonDB&lt;/res-ref-name&gt;
  &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
  &lt;res-auth&gt;Container&lt;/res-auth&gt;
  &lt;/resource-ref&gt;
  </code></pre>
  
  <p>web.xml: </p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="UTF-8"?&gt; 
     &lt;Context&gt;  
     &lt;Resource name="jdbc/UptonDB" auth="Container" type="javax.sql.DataSource" 
      removeAbandoned="true" removeAbandonedTimeout="30" maxActive="80"   
      maxIdle="30" maxWait="10000" username="*****" password="*******"
      driverClassName="org.postgresql.Driver"
      url = "jdbc:postgresql://127.0.0.1:5432/UptonDB" useUnicode="true"
      characterEncoding="utf-8" characterSetResults="utf8"/&gt;
     &lt;/Context&gt;
  </code></pre>
  
  <p>Any help is appreciated thanks! </p>