Search code examples
db2dbunit

DBUnit execute multiple statements on a DB2 database


I need to execute multiple SQL statements on a DB2 database from DbUnit. I tried to execute the statements this way:

connection.prepareStatement("statement1;statement2;").execute();

But the problem with this is that DB2 doesn't recognize ; as a statement terminator, so I get a SQL error with code -104.

It's possible to set the statement terminator when calling the SQL statement from command line using the -t parameter. But how can I do this from DbUnit?

I also tried putting --#SET TERMINATOR ; before the statements, but that didn't work.


Solution

  • It is not possible to pass several statements in a prepareStatement method. This is not related to DB2, but to JDBC, and as the method say, it is used to prepare ONE statement.

    You can use batch statement where you prepare multiple statements.

    Semi-colon is a statement separator in scripts, but there could be any other separator.