0

在查询中“_latin”在每个参数之前被连接起来

爪哇代码:

        PreparedStatement prepStmt = null;
        QueryString = "SELECT FROM Student WHERE username=? AND password=? ";
        prepStmt=con.prepareStatement(QueryString);
        prepStmt.setString(1,un);
        prepStmt.setString(2,pwd);
        ResultSet rs;

        System.out.println(prepStmt);
       rs = prepStmt.executeQuery();

错误 :

java.sql.SQLException: [MySQL][ODBC 5.1 Driver][mysqld-5.5.24-log]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM Student WHERE username=_latin1'wow' AND password=_latin1'hell'' at line 1

为什么会发生,解决方法是什么

这是表:

桌子

4

1 回答 1

0

您缺少查询中的列列表。您必须明确指定所需的列,或者通过通配符检索所有列。代替:

SELECT FROM Student WHERE username = ? AND password = ?

你想要这样的东西:

SELECT * FROM Student WHERE username = ? AND password = ?

请注意,显式定义要检索的列几乎总是比使用通配符表达式更好。

于 2012-12-08T19:46:00.813 回答