我试图运行一个prepare语句并在MySQL语法中出错。不确定是什么错误?
代码:
PreparedStatement stmt = null;
conn = ds.getConnection();
String query = "select distinct FName from PRL p1, RequestView p2 where p1.RequestId = p2.RequestId and p1.PackageId = p2.PackageId and p1.ProductId = ? and p1.ProductNumber = ? and p1.Version = ? order by p2.ArtName";
stmt = conn.prepareStatement(query);
stmt.setString(1,id);
stmt.setString(2,num);
stmt.setString(3,ver);
rs = stmt.executeQuery(query);
错误:
Caused by: com.mysql.jdbc.exceptions.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 p1.ESTProductMatNumber =? and p1.Version =? order by p2.ArtworkName' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
答案 0 :(得分:1)
没关系。我想到了。 rs = stmt.executeQuery(query);必须是rs = stmt.executeQuery();