0
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 2and的这段代码有错误line 4。我相信我的编码包含错误。

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

错误:

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

4

2 回答 2

0

尝试

conn = DriverManager.getConnection(connURL);//this is bad use a connection pool    
StringBuilder sb = new StringBuilder().append("Select * from inventory where functions");   
sb.append(" like ? order by brand, model");
String sqlStr  = sb.toString().intern();//use intern if this function is used many times
于 2013-05-15T14:57:35.080 回答
0

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

于 2013-05-15T12:20:08.093 回答