我正在尝试通过使用名字来搜索用户,这是数据库的第二列,但是每次尝试时,它告诉我即使在数据库中也找不到具有该用户名的用户
String usernamechk = txtflightname.getText();//txtflightname is the textfield to type the username to search for
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/airline","root","");
pst = con.prepareStatement("select * from flights where 'usernamechk' = ?");
pst.setString(1,usernamechk);
ResultSet rs = pst.executeQuery();
if(rs.next() == false)
{
JOptionPane.showMessageDialog(this, "user with this username not Found");
}
我将从检查您从中提取的值是否txtflightname.getText();
正确开始。尝试System.out.println(usernamechk)
检查文本中是否有空格。您可以像这样从其中删除空格:usernamechk.trim()
。最后,从查询中删除这些“”,然后将其表达为:
select * from flights where usernamechk = ?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句