conn = DriverManager.getConnection(connURL);
String sqlStr = "Select * from inventory where functions" + "like ? order by brand, model";

PreparedStatement pstmt = conn.prepareStatement(sqlStr);
pstmt.setString(1, "%" + search + "%");
ResultSet rs = pstmt.executeQuery();


大家好,我在line 2line 4处的这段代码有错误。我相信我的编码包含错误。

我怀疑我的SQL查询格式不正确。 pstmt.setString将在SQL查询中将search值设置为?

错误:

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 ''%null%' order by brand, model' at line 1

最佳答案

sql查询声明的语法错误。这就是为什么您会收到该错误。为什么在两者之间加上+?

关于mysql - 在制作SQL语句以在JSP中获取表和值时遇到问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16564803/

10-09 03:46