title: resultSet.next() throwing null pointer exception
body: <p>I'm working in java using the JDBC to perform queries on a database. For some reason, this code:</p>
  
  <pre><code>public static void checkAllFlights() {
      String SQLStatement = "SELECT Flight.FlightID,"
                              +"(CASE WHEN (SUM(NumSeats) &gt; 0) THEN SUM(NumSeats) ELSE 0 END)"
                              +"AS Booked_Seats,"
                              +"(CASE WHEN (MaxCapacity-SUM(NumSeats) &gt; 0) THEN MaxCapacity-SUM(NumSeats) ELSE MaxCapacity END) AS Available_Seats,"
                              +"MaxCapacity"
                              +"FROM Flight LEFT JOIN FlightBooking ON Flight.FlightID = FlightBooking.FlightID"
                              +"GROUP BY Flight.FlightID, Flight.MaxCapacity"
                              +"ORDER BY Flight.FlightID";
  
      try {
          dbAccess.getConnection();
          ResultSet resultSet = dbAccess.runSimpleQuery(SQLStatement);
          System.out.println("FlightID "+"Booked_Seats "+"Available_Seats "+"Max_Capacity");      
          while (resultSet.next()) {
              int ID = resultSet.getInt(1);
              System.out.println(ID);
          }
          DBAccess.disconnect();
      } catch (Exception e) {
          e.printStackTrace(System.err);
      } 
  }
  </code></pre>
  
  <p>is throwing me the error:</p>
  
  <pre><code>java.lang.NullPointerException
          at databases2.Databases2.checkAllFlights(Databases2.java:245)
          at databases2.Databases2.main(Databases2.java:26)
  </code></pre>
  
  <p>(line "245" refers to the "while (resultSet.next())")</p>
  
  <p>resultSet.next() and resultSet.close() on their own also produce the same error.</p>
  
  <p>I've used essentially the same code further up to cycle over a resultset and it worked fine and I've run the SQL directly and that returns the correct results so I'm confused as to why the resultSet.next() could be throwing a null pointer exception?</p>
  
  <p>The runSimpleQuery method:</p>
  
  <pre><code>public ResultSet runSimpleQuery(String sql)
          throws Exception {
  
      try {
          // Create a statement variable to be used for the sql query
          statement = connection.createStatement();
  
          // Perform the update
          return statement.executeQuery(sql);
      } catch (SQLException e) {
          // Problem encountered
          statement = null;
          return null;
      }
  </code></pre>
  
  <p>Update: After stepping through it, it does appear that runSimpleQuery is returning null which is something it shouldn't be doing unless an sql exception is throw....</p>
  
  <p><strong>Update:</strong> Solved. Whilst the query was right, apparently I messed up my string concatenation so that it didn't include spaces where it should and it worked when testing because I was an idiot and tested the query by copy-pasting from code rather than pulling the actual variable out of the debugger....</p>