[解决方法]org.dbunit.dataset.NoSuchTableException: Did not find table 'tab1' in schema 'null'

DBunit从本地数据库中取得dataset,利用dataset获取表名为'tab1'的表时报该错误,代码如下

Class.forName(Configuration.JDBC_DRIVE);
Connection conn =
    DriverManager.getConnection(Configuration.JDBC_URL,
                                Configuration.JDBC_USERNAME,
                                Configuration.JDBC_PASSWORD);
connection = new DatabaseConnection(conn);
DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
                   new MySqlDataTypeFactory());
IDataSet databaseDataSet = connection.createDataSet();
ITable actualTable = databaseDataSet.getTable(tableName);

奇怪的是在windows下该代码并不会报这个错误,linux下却有,网上查了很多资料,有说修改mysql表明大小写敏感值的,有说config.setProperty的FEATURE_CASE_SENSITIVE_TABLE_NAMES设为false的,结果都没解决问题, 后来想了折中的方法:FEATURE_CASE_SENSITIVE_TABLE_NAMES设为true,传入的tableName一律为大写,问题解决了。。。。代码如下

Class.forName(Configuration.JDBC_DRIVE);
Connection conn =
    DriverManager.getConnection(Configuration.JDBC_URL,
                                Configuration.JDBC_USERNAME,
                                Configuration.JDBC_PASSWORD);
connection = new DatabaseConnection(conn);
DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
                   new MySqlDataTypeFactory());
config.setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES,
                   Boolean.TRUE);
IDataSet databaseDataSet = connection.createDataSet();
ITable actualTable = databaseDataSet.getTable(tableName);


你可能感兴趣的:([解决方法]org.dbunit.dataset.NoSuchTableException: Did not find table 'tab1' in schema 'null')