我是编程新手。我正在尝试制作一个软件。但我有问题。
问题是:我的软件是校务管理。因此,当我在 java 中输入学生卷号时,我需要检索我存储在 mysql 中的他的信息(姓名、年龄等)。但是我输入的代码总是为我输入的任何滚动提供相同的信息。请帮忙
String LibraryCardNo = txtCard.getText();
String firstName = "";
String lastName = "";
String Job = "";
String Age = "";
String LibraryCard = "";
try{
Class.forName("java.sql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3307/library?" + "user=root&password=ainkhalid");
Statement s = con.createStatement();
String query = "select * from application";
ResultSet rs = s.executeQuery(query);
while(rs.next()){
firstName = rs.getString("firstName");
lastName = rs.getString("lastName");
Job = rs.getString("job");
Age = rs.getString("age");
LibraryCard = rs.getString("LibraryCardNo");
}
rs.close();
s.close();
con.close();
}
catch(Exception e){
String msg = e.getMessage();
System.out.println("The problem is :"+msg);
}
txtLast.setText(lastName);
txtFirst.setText(firstName);
txtJob.setText(Job);
txtAge.setText(Age);