title: java.lang.NullPointerException with variable having a value (Eclipse)
body: <p>I have looked throughout the web to try to find an answer to my error, but nothing I have found matches my error or I fail to understand the relation.</p>
  
  <p>Here is my error running on eclipse:</p>
  
  <blockquote>
    <p>java.lang.NullPointerException
        ca.sheridancollege.controllers.CarDealership.doGet(CarDealership.java:63)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
        org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)</p>
  </blockquote>
  
  <p>and here is my code:</p>
  
  <pre><code>package ca.sheridancollege.controllers;
  
  import java.io.IOException;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  /**
   * Servlet implementation class CarDealership
   */
  @WebServlet("/CarDealership")
  public class CarDealership extends HttpServlet {
  private static final long serialVersionUID = 1L;
  
  /**
   * @see HttpServlet#HttpServlet()
   */
  public CarDealership() {
      super();
      // TODO Auto-generated constructor stub
  }
  
  /**
   * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      String dbURL= "jdbc:mysql://localhost:3306/SheridanUsedCars";
      String user = "root";
      String password = "1234";
      Connection conn = null;
      try {
          conn = DriverManager.getConnection(dbURL, user, password);
      } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      String retrieve = "SELECT manufacturerID, manufacturer, price FROM car INNER JOIN manufacturer GROUP BY manufacturerID";
      PreparedStatement ps = null;
      try {
          ps = conn.prepareStatement(retrieve);
      } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      ResultSet rs = null;
      try {
          rs = ps.executeQuery();
      } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      System.err.println("Error executing "+ps.toString());
      try {
          while (rs.next()){
              int id = rs.getInt("manufacturerID");
              String man = rs.getString("manufacturer");
              response.getWriter().append("&lt;h1&gt;"+id+" "+man+"&lt;/h1&gt;");
          }
      } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  }
  
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      doGet(request, response);
  }
  
  }
  </code></pre>
  
  <p>it seems to me like it thinks rs is null, is it because of the try catch? I cant seem to get it going.
  any help is <em>really</em> appreciated</p>