String stuNumber=txtNumber.getText(); //得到文本框中你输入学号学号
连接查询:
PreparedStatement ps = null;
ResultSet rs = null;
Connection conn = DriverManager.getConnection(url,username,password);
ps = conn.prepareStatement("select name from student where number = ?");
ps.setString(1, stuNumber);
rs = ps.executeQuery();
while(rs.next()){
String stuName = rs.getString("name");
}
然后,把查出的姓名给文本框
txtName.setText(stuName);
Statement stmt = con.createStatement();
ResultSet rs=null;
rs=stmt.executeQuery("SQL查询语句");
//rs会得到所有查询结果