1. 程式人生 > >mysql+dbunit 丟擲NoSuchColumnException、DataSetException

mysql+dbunit 丟擲NoSuchColumnException、DataSetException

使用mysql + dbunit進行單元測試時,經常會丟擲類似如下異常:
org.dbunit.dataset.DataSetException: java.sql.SQLSyntaxErrorException: Unknown table 't_user' in information_schema
org.dbunit.dataset.NoSuchColumnException: t_user.ID -  (Non-uppercase input column: id) in ColumnNameToIndexes cache map. Note that the map's column names are NOT case sensitive.
google、baidu上也沒有有效的解決辦法。閱讀dbunit的原始碼發現,其已經為mysql提供了專用Connection。初始化dbunit的DatabaseConnection時,使用如下的類即可解決以上問題:
IDatabaseConnection con = new MySqlConnection(DbUtil.getConnection(), "itat_junit");