Java 如何检查数据库表中是否存在字符串
但生成的结果为空,其他用户的详细信息也被排除。尝试修改后的查询,并动态传递参数,如下所述Java 如何检查数据库表中是否存在字符串,java,jdbc,Java,Jdbc,但生成的结果为空,其他用户的详细信息也被排除。尝试修改后的查询,并动态传递参数,如下所述 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
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});
}
Username=SQL中的Username表示每条记录。与not组合表示没有记录。请查看绑定参数。
// 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();