MySQLSyntaxErrorException:WHERE子句

时间:2016-07-23 00:41:00

标签: java mysql database jdbc

我试图从我的数据库中检索数据。但是,它给我一个错误:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'WHERE FORMID = 120002013 AND CLASSIFICATION = 'Private'' at line 1

以下是我检索数据的代码:

try (Connection conn = myFactory.getConnection()) {
    PreparedStatement pstmt = conn.prepareStatement("SELECT CENSUSYEAR, SCHOOLID, CLASSIFICATION, SCHOOLNAME" +
    "FROM DIRECTORY_SCHOOL WHERE FORMID = ? AND CLASSIFICATION = ?");
    pstmt.setInt(1, formID);
    pstmt.setString(2, classification);
    ResultSet rs = pstmt.executeQuery();

似乎有什么问题?谢谢!

1 个答案:

答案 0 :(得分:1)

" SCHOOLNAME" +" FROM"使它成为SCHOOLNAMEFROM