Search
Calendar
April 2024
S M T W T F S
« Sep    
 123456
78910111213
14151617181920
21222324252627
282930  
Your widget title
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:

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