【发布时间】:2021-02-08 06:44:25
【问题描述】:
我正在尝试使用数据库中第二列的名字来搜索数据库中的用户,但每次我尝试它时,它都会告诉我即使它存在于 db 中也找不到具有此用户名的用户
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() 替换为 txtflightname.getText().toString().trim()