-3
我試圖從我的數據庫檢索數據。然而,它給我的錯誤:MySQLSyntaxErrorException:WHERE子句
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();
出了什麼問題?謝謝!
我的猜測是,你需要一個空間,在你'from'條款面前 - 目前你正在寫'選擇... schoolnamefrom directory_school哪裏...' – sgeddes
嘗試打印您的SQL查詢。注意'SCHOOLNAME「+」FROM「的結果。 – Pshemo