2017-11-28 5 views
0

Java 및 MySQL을 사용하면 while 루프는 쿼리를 만족하는 마지막 레코드 만 반환합니다. 쿼리는 MySQL Workbench에서 쿼리를 실행하는 것에 따라 정확 해 보입니다. 둘 이상의 레코드가 리턴되어야합니다.JDBC, SELECT 문은 마지막 레코드 만 반환합니다.

Statement statement2 = connection.createStatement();

 String entryCrew = crewFlight.getText(); 
    String s2 = "select airemployee.eid, airemployee.Fname, airemployee.lname, airemployee.phone, airemployee.JobDescription, airemployee.AircraftID, airemployee.salary, flightno\n" + 
    "from airemployee inner join flight on airemployee.aircraftID = flight.aircraftID where flightno = '"+entryCrew+"'"; 
    ResultSet rs2 = statement2.executeQuery(s2); 


    while (rs2.next()){ 
    outputArea.setText("EID:"+rs2.getInt("EID")+"---"+"First Name:"+rs2.getString("FName")+"---"+"Last Name:"+rs2.getString("LName")+"---"+"Phone:"+rs2.getString("Phone")+"---"+"Job:"+rs2.getString("JobDescription")+"---"+"AircraftID:"+rs2.getInt("AircraftID")+"---"+"Salary:"+rs2.getInt("Salary")); 
    } 
    } 
    catch (Exception exc){ 
     JOptionPane.showMessageDialog(null, exc); 
    } 
}            

답변

1

setText가 누적되지 않습니다. while 루프의 모든 단계는 거기에있는 내용을 덮어 쓰며 끝에 최종 레코드 데이터 만 남깁니다.

StringBuffer에 모아서 끝에 설정하십시오.