[英]last insterted record does not reflect in select statement in mysql using JDBC
[英]JDBC, SELECT statement only returns last record.
使用Java和MySQL,while循环仅返回满足查询条件的最后一条记录。 基于在MySQL Workbench中运行查询,该查询似乎是正确的。 应该有多个记录被返回。
语句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);
}
}
setText不累积。 while循环中的每一步都会覆盖那里的内容,最后只保留最终的记录数据。
收集到StringBuffer中并在末尾设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.