My question is that I want to retrieve marks between a lowest and highest range from a database. The user is prompted to enter the lowest and highest range from the keyboard. I have a problem in my sql query where it is not recognising the cpa1 & cpa2 range that I have specified from the keyboard input. Please help.
See my codes below:
try{
Scanner input = new Scanner(System.in);
System.out.print("Kindly enter the lowest CPA threshold : ");
cpa1 = input.nextFloat();
System.out.println();
System.out.println("Kindly enter highest CPA threshold : ");
cpa2 = input.nextFloat();
rs = stt.executeQuery("SELECT * FROM student WHERE CPA BETWEEN `cpa1` and `cpa2` order by CPA asc");
while(rs.next()){
String id = rs.getString("student_id");
String name = rs.getString("student_name");
String gender = rs.getString("gender");
float cpa = rs.getFloat("CPA");
Date enrol = rs.getDate("enrollment_date");
try{
FileWriter writer = new FileWriter("StudentRange.txt");
}catch(Exception e){
e.printStackTrace();
}
}
input.close();
}catch(Exception e){
e.printStackTrace();
}
stt? I highly doubt you can specify thecpa1andcpa2substitution values like you are doing withexecuteQuery.