1

I'm using Java with an SQL library to work with a spreadsheet I uploaded to an Oracle Database. I calculated student scores that are one standard deviation away from the mean score, and used the "getFloat" method to retrieve the values from the columns as floats. The reason why I did this was to later use those values to compare them in an if statement. However, when I compile, I get a data type mismatch error. The errors occur in the following lines:

float AllScores = selectScore.getFloat("SCORES");
float totalAvg = avgScore.getFloat("SCORE_AVG"); 
float ScoreStDev = sdev.getFloat("standardDeviation");

I know that I'm getting these errors because I am trying to get float values from a variable that I declared as a String, which holds the "SELECT" statement. My question is, how can I retrieve the float value from the columns to compare it later in my if statement. Some of my code:

 String selectScore = "SELECT SCORES FROM STUDENTS";
 st.executeQuery(selectScore);

 String avgScore = "SELECT Avg(SCORES) AS SCORE_AVG FROM STUDENTS";
 rs = st.executeQuery(avgScore);
 String sdev = "SELECT STDEV(SCORES) AS standardDeviation FROM STUDENTS";
 st.executeQuery(sdev);

int one = 1;


           //Loop score column
           while(rs.next()){

           //Convert values into float values
           float AllScores = selectScore.getFloat("SCORES");
           float totalAvg = avgScore.getFloat("SCORE_AVG"); 
           float ScoreStDev = sdev.getFloat("standardDeviation");

            //Calculate 1 standard deviation away from mean
           float theSD = AllScores - (one * ScoreStDev);
           }

              if(SCORE > ScoreStDev){
              //Code here

             }

Any help would be appreciated!

4

1 回答 1

0

这是因为您尝试getFloat使用 Query 字符串而不是ResultSetget from each executeQuery()。例如:

String selectScore = "SELECT SCORES FROM STUDENTS";
ResultSet rs = st.executeQuery(selectScore);

....

float AllScores = rs.getFloat("SCORES");
于 2013-07-18T20:39:24.540 回答