title: Cannot be resolved to a variable - JDBC
body: <p>I am working with an Oracle Database using Java and an SQL library. I'm trying to calculate students whose averages are one standard deviation away from the mean, add a column to flag those students, and count how many students meet the criteria and add them to a new table. I am getting an error that says the "allAvgs" variable and "theSD" variable "cannot be resolved to a variable". The error happens in my if statement, but I have already instantiated those variables. Why do I get this error? Any help is appreciated.</p>
  
  <pre><code>try{
           Statement stOne, stTwo, stThree, stFour;
           String SelectAverage = "SELECT MEAN FROM STUDENTS";
            ResultSet rsOne = stOne.executeQuery(SelectAverage);
  
      String TotalAverage = "SELECT Avg(MEAN) AS averages FROM STUDENTS";
            ResultSet rsTwo = stTwo.executeQuery(TotalAverage);     
  
            String student_stan_dev = "SELECT STDEV(MEAN) AS standardDeviation FROM STUDENTS";
            ResultSet rsThree = stThree.executeQuery(student_stan_dev);
  
             int onesdMean = 1;
  
  
             //Loop Duration_Sec column
             while(rsOne.next()){
  
             //Convert values into float values
             float allAvgs = rsOne.getFloat("MEAN");
             float totalAvg = rsTwo.getFloat("averages"); 
             float StDev = rsThree.getFloat("standardDeviation");
  
             float theSD = allAvgs - (onesdMean * StDev);
             }
  
          String flaggedStudents = "ALTER TABLE STUDENTS ADD FlaggedStudents INT";
          ResultSet rsFour = stFour.executeUpdate(flaggedStudents);
  
             if(allAvgs &gt;= theSD){
                 String FlagHint = "INSERT INTO STUDENTS.FlaggedStudents VALUES('1')";
                 st.executeUpdate(FlagHint);
             }
  
          String countInstances = "SELECT STUDENTS.NAME, STUDENTS.FlaggedStudents" +
                  "COUNT(*)OVER(PARTITION BY STUDENTS) AS cnt FROM STUDENTS";
             st.executeQuery(countInstances);
  
  
          st.executeUpdate("CREATE TABLE IF NOT EXISTS StudentCount" +
          "(NAME INT , cnt INT)");
  
          String insertVals = String.format("INSERT INTO StudentCount" +
                  "(NAME , cnt INT") +
                  " VALUES ('%s','%s')");
  
          st.execute(insertVals);enter code here
  </code></pre>