将变量传递给SQL语句以选择特定记录

时间:2017-05-18 22:07:28

标签: java sqlite

好的,我有一个登录系统,我需要提取每个特定用户记录中的所有信息,并在登录后显示给他们

public void info(){

    String sql = "SELECT name, surname, age, username FROM member WHERE username = 'Custom Hue'";

    try (
            Statement stmt  = connection.createStatement();
            ResultSet rs    = stmt.executeQuery(sql)){

        // loop through the result set
        while (rs.next()) {
            String fname = rs.getString("name");           
            String sname = rs.getString("surname"); 
            int age = rs.getInt("age");       
            String uname = rs.getString("username");

            lblFName.setText(fname);
            lblSName.setText(sname);
            lblAge.setText(String.valueOf(age));
            lblUName.setText(uname);
        }
    } catch (SQLException e) {
        System.out.println(e.getMessage());
    }


}

上图:我只需要将数据库中的特定用户名放入查询中,即可获得所需的所有信息并正确删除

我有这段代码,它显示从登录阶段拉出的标签中的用户用户名

    public void GetUser(String user) {
    // TODO Auto-generated method stub
    usernameLabel.setText("Welcome back, " + user + "!");
}

有没有办法可以推送GetUser方法或将usernameLabel放在我目前拥有'Custom Hue'的位置

1 个答案:

答案 0 :(得分:2)

据我了解你需要这个吗?

$(function() {
  $('#kill').on('click', function() {
    // If you know it's the fourth one on you want to remove:
    $('tr > td').filter(function(index, el) {
      return index > 2;
    }).remove();
    // If you only know it's the cells after the one with "21" in it
/*
      var found = false;
    $('tr > td').filter(function(index, el) {
      var skip = false;
      if (!found) {
         found = el.textContent.substring(0, 2) == '21';
         skip = true;
      }
      return found && !skip;
    }).remove();
*/
  });
});