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 2
和line 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/