1 String n = user.getName();
2 String pass = user.getPassword(); 3 String sql = "select * from user where name = " + n + " and password = " + pass; 4 PreparedStatement ps = con.prepareStatement(sql);
第三句有问题MySQLSyntaxErrorException: Unknown column 'huoyingfans' in 'where clause'
2 String pass = user.getPassword(); 3 String sql = "select * from user where name = " + n + " and password = " + pass; 4 PreparedStatement ps = con.prepareStatement(sql);
第三句有问题MySQLSyntaxErrorException: Unknown column 'huoyingfans' in 'where clause'
public boolean checkUser() throws Exception {
boolean flag = false;
if (user != null) {
try {
String n = user.getName();
String pass = user.getPassword(); ????? String sql = "select * from user where name = " +
'n' + " and password = " + 'pass'; PreparedStatement ps = con.prepareStatement(sql); if (null != ps.executeQuery()) {
flag = true;
}
// 关闭连接
ps.close();
con.close(); } catch (Exception e) {
e.printStackTrace();
}
} return flag;
}这样写 有语法错误
楼主换成这个试试
n + "' and password = '" + pass + "'";
Unknown column 'huoyingfans' in 'where clause'