按照教程操作到2-6,代碼和教程的一樣,軟件也一樣,出不來,控制臺報(bào)錯(cuò),意思是說我的sql代碼有問題,可是,我是完全抄的教程啊。我把代碼貼出來。請大佬指點(diǎn)一下。
List<String> paramList = new ArrayList<String>();
?? ??? ??? ?if (command != null && !"".equals(command.trim())) {
?? ??? ??? ??? ?sql.append("and COMMAND=?");
?? ??? ??? ??? ?paramList.add(command);
?? ??? ??? ?}
?? ??? ??? ?if (description != null && !"".equals(description.trim())) {
?? ??? ??? ??? ?sql.append("and DESCRIPTION like '%'?'%'");
?? ??? ??? ??? ?paramList.add(description);
?? ??? ??? ?}
?? ??? ??? ?PreparedStatement statement = conn.prepareStatement(sql.toString());
?? ??? ??? ?for (int i = 0; i < paramList.size(); i++) {
?? ??? ??? ??? ?statement.setString(i + 1, paramList.get(i));
?? ??? ??? ?}
?? ??? ??? ?ResultSet rs = statement.executeQuery();
控制臺報(bào)錯(cuò)如下:
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 'COMMAND='??????'and DESCRIPTION like '%''??????''%'' at line 1
2020-05-25
where 1=1和and xxx中間少空格了吧
2020-02-25
sql語句拼接的時(shí)候有問題