2014-08-31 105 views
0
Class.forName("com.mysql.jdbc.Driver"); 
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hibernate","root","root"); 
String query1= "select * from registration where email= ? and password= ? "; 
PreparedStatement ps = con.prepareStatement(query1); 
ps.setString(1,email); 
ps.setString(2,password); 
ResultSet rs1= ps.executeQuery(query1); 
rs1.next(); 
String s= rs1.getString("type"); 
out.println(s); 

我收到以下錯誤 -爲什麼我得到錯誤語法錯誤?

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 '? and password= ?' at line 1 

回答

3
ps.executeQuery(query1) 

必須改變,以

ps.executeQuery() 

否則,你不執行與綁定參數準備好的查詢,但沒有準備好查詢,沒有任何參數綁定。

+0

然後如何執行查詢,如果我不指定查詢1裏面ps.executeQuery()像ps.executeQuery(query1) – user3871262 2014-09-01 08:17:51

+0

謝謝我得到它和它的工作 – user3871262 2014-09-01 08:27:26

相關問題