Recent Posts
Archives

Posts Tagged ‘Table … not found in tableMap=org.dbunit.dataset.OrderedTableNameMap[_tableNames=[]’

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:

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

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():

[java]final PreparedStatement preparedStatement;
preparedStatement = getDatabaseTester().getConnection().getConnection().prepareStatement("CREATE TABLE Jonathan_Lalou_Table … ");
preparedStatement.executeUpdate();[/java]