gpt4 book ai didi

java - 如何检查数据库表中是否存在字符串

转载 作者:行者123 更新时间:2023-12-02 10:11:34 25 4
gpt4 key购买 nike

 String s="abcd";  // The user that needs to be excluded in the table, 
the string can be dynamic.

String sql="SELECT Username,Email FROM login where not
Username=userName"; //here I use the query not to exclude the particular user.


PreparedStatement pst = con.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while(rs.next()){
inputString=(String)rs.getString("Username");
model.addRow(new Object[{rs.getString("Username"),rs.getString("Email"),false});

}

但生成的结果为空,其他用户的详细信息也被排除。

最佳答案

尝试修改后的查询并动态传递参数,如下所述。

// The user that needs to be excluded in the table, the string can be dynamic.
String s="abcd";

//here I use the query not to exclude the particular user.
String sql="SELECT Username,Email FROM login where Username != ?";

PreparedStatement pst = con.prepareStatement(sql);
pstatement.setString(1, s);
ResultSet rs = pst.executeQuery();

关于java - 如何检查数据库表中是否存在字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54968748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com