Search
Calendar
May 2025
S M T W T F S
« Apr    
 123
45678910
11121314151617
18192021222324
25262728293031
Archives

PostHeaderIcon Table … not found in tableMap=org.dbunit.dataset.OrderedTableNameMap[_tableNames=[], _tableMap={}, _caseSensitiveTableNames=false]

Case

On a unit test with JDBC / DBUnit, extending org.dbunit.DBTestCase, I get this error:

Table 'Jonathan_Lalou_Table' not found in tableMap=org.dbunit.dataset.OrderedTableNameMap[_tableNames=[], _tableMap={}, _caseSensitiveTableNames=false]

Explanation and fix

Indeed, even when you provide a dataset through a flat XML file, DBUnit does not create the tables, but only fills them in. I know, this is paradoxal and most developpers would like to create implicitly the tables prior to filling them…

To fix the issue, add a block like this one, for instance when overriding the method getDataSet():

final PreparedStatement preparedStatement;
preparedStatement = getDatabaseTester().getConnection().getConnection().prepareStatement("CREATE TABLE Jonathan_Lalou_Table ... ");
preparedStatement.executeUpdate();

Leave a Reply