简体   繁体   English

mysql中带有preparedstatement的查询中的问题

[英]issue in query with preparedstatement in java with mysql

in query "_latin" is getting concatenated before every param 查询“ _latin”中的参数在每个参数之前被串联

java code : Java代码:

        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();

error : 错误:

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

why its happening , whats the solution 为什么会发生,解决方案是什么

and this is table : 这是表:

表

You are missing the column list from your query. 您缺少查询中的列列表。 You have to either specify explicitly the columns you want, or retrieve all via wildcard. 您必须明确指定所需的列,或者通过通配符检索所有列。 Instead of: 代替:

SELECT FROM Student WHERE username = ? AND password = ?

You want something like: 您想要类似的东西:

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

Note that its almost always better to explicitly define the columns you want to retrieve, rather than using the wildcard expression. 请注意,与使用通配符表达式相比,显式定义要检索的列几乎总会更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM