0
QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());
        qr.update("DELETE FROM course_access " +
                "WHERE user_id = ? " +
                "AND course_id NOT IN (?)", user_id, courseIdList);

String user_id = "2"
String courseIdList = "101,102,104,105,106,108,109"
But the results are not correct
only the result same as

DELETE FROM course_access WHERE user_id=2 AND course_id NOT IN (101)

The table structure looks like this

id  course_id  user_id
1    101          1
2    102          1
3    105          1
4    104          1
5    106          1
6    108          1
11   110          1
12   101          2
26   101          8
27   102          8
28   105          8
29   104          8
30   106          8
31   108          8
32   110          8
33   113          8
34   115          1
35   107          1
36   115          8
37   109          8
38   109          1
39   107          8
40   116          8
41   116          1
98   102          2
99   103          2
100  104          2
101  105          2
102  106          2
103  107          2
104  108          2
105  109          2
EastLord
  • 1
  • 3
  • You cannot pass in a list like that. If there are only a few entries, the easiest way is to loop over the list and issue multiple queries (one for each courseId). – Thilo Sep 27 '17 at 07:49
  • what kind of type courseIdList is? – Maistrenko Vitalii Sep 27 '17 at 07:50
  • You could also try to use `QueryRunner#batch`, but support for that may not be so great for all databases: https://commons.apache.org/proper/commons-dbutils/apidocs/org/apache/commons/dbutils/QueryRunner.html#batch-java.lang.String-java.lang.Object:A:A- – Thilo Sep 27 '17 at 07:53
  • I think `QueryRunner#batch` can not meet my requirements – EastLord Sep 27 '17 at 09:27
  • 1
    https://stackoverflow.com/questions/19033628/how-do-i-pass-a-list-set-array-to-apache-queryrunner-as-parameter-value – Joop Eggen Sep 27 '17 at 09:32

0 Answers0