import com.mysql.jdbc.Connection;
import db.DBConnector;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by shimin on 9/24/2014.
 */
public class Controller extends DBConnector {

    private double temperature = 0.0;
    private int lighting;
    private int pressure;
    private int humidity;
    private int sound;
    private int sensorID;

    /*
     * A database connection is available through the inherited field 'connection'.
     */

    public double getTemperature(){
        String query =  "SELECT Value FROM TemperatureSample JOIN (" +
                        "SELECT MAX(Date) as MaxDate FROM TemperatureSample AS T1" +
                        ") AS T2 WHERE Date = MaxDate";

        try {
            preparedStatement = connection.prepareStatement(query);
            preparedStatement.execute();
            ResultSet results = preparedStatement.getResultSet();
            results.next();
            temperature = results.getDouble(1);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return temperature;
    }

    public int getLighting(){ return lighting;}

    public int getPressure(){return pressure;}

    public int getHumidity(){return humidity;}

    public int getSound(){return sound;}

    public int getSensorID(){return sensorID;}

    public static void main(String[] args){
        Controller ctrl = new Controller();
        ctrl.connect();
        System.out.println(ctrl.getTemperature());
    }
}

@@ -1,1506 +1,73 @@
-import com.mysql.jdbc.Connection;%0Aimport db.DBConnector;%0A%0Aimport java.sql.ResultSet;%0Aimport java.sql.SQLException;%0A%0A/**%0A * Created by shimin on 9/24/2014.%0A */%0Apublic class Controller extends DBConnector %7B%0A%0A    private double temperature = 0.0;%0A    private int lighting;%0A    private int pressure;%0A    private int humidity;%0A    private int sound;%0A    private int sensorID;%0A%0A    /*%0A     * A database connection is available through the inherited field 'connection'.%0A     */%0A%0A    public double getTemperature()%7B%0A        String query =  %22SELECT Value FROM TemperatureSample JOIN (%22 +%0A                        %22SELECT MAX(Date) as MaxDate FROM TemperatureSample AS T1%22 +%0A                        %22) AS T2 WHERE Date = MaxDate%22;%0A%0A        try %7B%0A            preparedStatement = connection.prepareStatement(query);%0A            preparedStatement.execute();%0A            ResultSet results = preparedStatement.getResultSet();%0A            results.next();%0A            temperature = results.getDouble(1);%0A        %7D catch (SQLException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A        return temperature;%0A    %7D%0A%0A    public int getLighting()%7B return lighting;%7D%0A%0A    public int getPressure()%7Breturn pressure;%7D%0A%0A    public int getHumidity()%7Breturn humidity;%7D%0A%0A    public int getSound()%7Breturn sound;%7D%0A%0A    public int getSensorID()%7Breturn sensorID;%7D%0A%0A    public static void main(String%5B%5D args)%7B%0A        Controller ctrl = new Controller();%0A        ctrl.connect();%0A        System.out.println(ctrl.getTemperature());%0A    %7D
+%0A/**%0A * Created by shimin on 9/24/2014.%0A */%0Apublic class Controller %7B%0A
 %0A%7D%0A

Move responsibility of SQL queries DBManager (different branch)