2012-12-08 48 views
0

查詢 「_latin」 是越來越每PARAM之前串接問題與查詢的PreparedStatement在Java和MySQL

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

錯誤:

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 

爲什麼它的發生,最新解決方案

這是表格:

table

+0

你的un和pwd是什麼? –

+2

您錯過了您的專欄列表。 – Perception

回答

0

您缺少查詢中的列列表。您必須明確指定所需的列,或者通過通配符來檢索所有列。相反的:

SELECT FROM Student WHERE username = ? AND password = ? 

你想要的東西,如:

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

注意,它幾乎總是最好明確定義要檢索的列,而不是使用通配符表達式。