0

We need to use a third party lib to execute SQL statements and before to start implementing we would like to be sure that the lib can do whatever we want. We are currently evaluating Apache DBUtils.

We tried to execute a query like

INSERT INTO MyTable(ColA, ColB, ColC) VALUES (?, ?, ?),
                                             (?, ?, ?),
                                             (?, ?, ?);

using insertBatch, but it looks like it fails because it wants to run something like:

INSERT INTO MyTable(ColA, ColB, ColC) VALUES (?, ?, ?);
INSERT INTO MyTable(ColA, ColB, ColC) VALUES (?, ?, ?);
INSERT INTO MyTable(ColA, ColB, ColC) VALUES (?, ?, ?);

which is worse from the point of view of the performance.

Are we doing something wrong? Is there any way to achieve the former SQL statement using Apache DBUtils?

mat_boy
  • 12,998
  • 22
  • 72
  • 116

1 Answers1

6

I guess you're supposed do something like this:

queryRunner.batch("INSERT INTO MyTable(ColA, ColB, ColC) VALUES (?, ?, ?)",
        new Object[][] {
            {"A1", "B1", "C1"},
            {"A2", "B2", "C2"},
            {"A3", "B3", "C3"}});
Maurice Perry
  • 9,261
  • 2
  • 12
  • 24