Query for searching the name alphabetically

前端 未结 5 1179
梦谈多话
梦谈多话 2020-12-12 06:04

I have used the LIKE condition, but it required me to enter the full name into the database to find the name.



        
5条回答
  •  有刺的猬
    2020-12-12 06:28

    You need to iterate over the result set:

    while (rs.next()) {
        String name = rs.getString("Name");
        System.out.println("Name: " + name);
    }
    

    It looks like you had it and commented it out? If you want to store it in a list you had it right. If you want to put all of the results into a String for that tasearch.setText() you could:

    StringBuilder sb = new StringBuilder();
    while (rs.next()) {
        String name = rs.getString("Name");
        sb.append(name + " ");
    }
    String names = sb.toString().trim();
    tasearch.setText(names);
    

提交回复
热议问题