Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java org.dbunit.dataset.NoSuchTableException错误数据库dataset-表';行程';找不到_Java_Mysql_Dbunit - Fatal编程技术网

Java org.dbunit.dataset.NoSuchTableException错误数据库dataset-表';行程';找不到

Java org.dbunit.dataset.NoSuchTableException错误数据库dataset-表';行程';找不到,java,mysql,dbunit,Java,Mysql,Dbunit,我一直在bing/google(boogle)搜索,我发现了一些点击(主要是在stackoverflow上),我试图应用建议的解决方案,但运气不佳 我正在使用Java8和DbUnit2.5.1以及mysql连接器Java5.1.36和mysql(版本14.14发行版5.6.15,用于Win64(x86_64)) 我正在阅读一个以前由DBUnit创建的XML文件,该文件定义了几个表,其中一个称为“trip”。我的mysql实例有一个名为“dbunit”的空数据库,我的期望是我的代码将读取XML并用

我一直在bing/google(boogle)搜索,我发现了一些点击(主要是在stackoverflow上),我试图应用建议的解决方案,但运气不佳

我正在使用Java8和DbUnit2.5.1以及mysql连接器Java5.1.36和mysql(版本14.14发行版5.6.15,用于Win64(x86_64))

我正在阅读一个以前由DBUnit创建的XML文件,该文件定义了几个表,其中一个称为“trip”。我的mysql实例有一个名为“dbunit”的空数据库,我的期望是我的代码将读取XML并用表填充数据库“dbunit”,用XML文件中的数据填充表行

这是我的数据文件的一个片段,由dbunit从mysql数据库“pocketguide3rded”(基于SQL PocketGuide第三版)创建

我在调用CLEAN_INSERT.execute时遇到此异常

下面是我尝试运行junit测试的结果

JUnit版本4.11

.ERROR DatabaseDataSet-在tableMap=org.dbunit.dataset.OrderedTableNameMap[\u tableNames=[],\u tableMap={},\u caseSensitiveTableNames=true]中找不到表“trip”

E

时间:0.464

有1次失败:

1) test5_Test(com.heintze.demos.wikidot_com_demoimportexport.demobunit)

org.dbunit.dataset.NoSuchTableException:行程 位于org.dbunit.database.DatabaseDataSet.getTableMetaData(DatabaseDataSet.java:288),位于org.dbunit.operation.deleteAllooperation.execute(deleteAllooperation.java:109) 在org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:79) 位于com.heintze.demos.wikidot_com_demoimportexport.demobunit.fullDatabaseImport(demobunit.java:265) 在com.heintze.demos.wikidot_com_demoimportexport.demobunit.test5_Test(demobunit.java:249) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中 位于java.lang.reflect.Method.invoke(Method.java:483) 位于org.junit.runners.model.FrameworkMethod$1.runReflectVeCall(FrameworkMethod.java:47) 位于org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 位于org.junit.runners.model.FrameworkMethod.invokeeexplosive(FrameworkMethod.java:44) 位于org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) 位于org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 位于org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 位于org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 位于org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 位于org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 位于org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 访问org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 位于org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 位于org.junit.runners.ParentRunner.run(ParentRunner.java:309) 位于org.junit.runners.Suite.runChild(Suite.java:127) 位于org.junit.runners.Suite.runChild(Suite.java:26) 位于org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 位于org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 位于org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 访问org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 位于org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 位于org.junit.runners.ParentRunner.run(ParentRunner.java:309) 位于org.junit.runner.JUnitCore.run(JUnitCore.java:160) 位于org.junit.runner.JUnitCore.run(JUnitCore.java:138) 位于org.junit.runner.JUnitCore.run(JUnitCore.java:117) 位于org.junit.runner.JUnitCore.runMain(JUnitCore.java:96) 位于org.junit.runner.JUnitCore.runMainAndExit(JUnitCore.java:47) 位于org.junit.runner.JUnitCore.main(JUnitCore.java:40)

失败!!! 测试运行:1,失败:1


/cygdrive/c/Users/siegfried/Documents/spring工具套件工作区/DBUnitDemo/wikidot com demoimportexport/src/test/java/com/heintze/demos/wikidot_com_demoimportexport

问题在于DBUnit只是用数据填充表格。它实际上并不创建表。我通过如下方式重写getSetupOperation解决了此问题:

@Override
    protected DatabaseOperation getSetUpOperation() throws Exception
    {
        dbConnection = DriverManager.getConnection("jdbc:hsqldb:mem:tests", "sa", "");
        createTables();
        return DatabaseOperation.REFRESH;
    }

    private void createTables() throws Exception {
        PreparedStatement statement = dbConnection
                .prepareStatement("CREATE TABLE digidauthsessions ( "
                        + "id INTEGER IDENTITY NOT NULL PRIMARY KEY,"
                        + "request_token VARCHAR(50) NOT NULL,"
                        + "response_token VARCHAR(50) NOT NULL,"
                        + "relatienr VARCHAR(50) NOT NULL,"
                        + "digidnameid VARCHAR(1000) NOT NULL" + ")");
        statement.execute();
        statement.close();
    }

在这里,在getSetupOperation中,我直接连接到我的hsql测试数据库。通过这种连接,我可以调用createTables方法,该方法实际上创建了我的表。这是在这个重写方法中完成的,因为这样我确信表总是在

Wow!快一年了,我收到了你的回复!非常感谢。奇怪的是,无论是文档还是任何教程都没有让创建表的细节变得更加明显。
    public static void fullDatabaseImport(File file) throws     ClassNotFoundException, 
                                                            DatabaseUnitException, 
                                                            IOException,
                                                            SQLException {
    IDatabaseConnection connection = getConnection();
    IDataSet dataSet = new FlatXmlDataSet(file, true);

    DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
    //DatabaseOperation.INSERT.execute(connection, dataSet);
}

public static IDatabaseConnection getConnection() throws     ClassNotFoundException, 
                                                            DatabaseUnitException, 
                                                            SQLException {
    // database connection
    Class driverClass = Class.forName(_driverClass);
    Connection jdbcConnection = DriverManager.getConnection(_jdbcConnection, username, password);
    IDatabaseConnection dbConn = new DatabaseConnection(jdbcConnection/*,"dbunit"*/);
    dbConn.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new MySqlDataTypeFactory());
    dbConn.getConfig().setProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER, new MySqlMetadataHandler());
    dbConn.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, Boolean.TRUE);

    return dbConn;  
}
@Override
    protected DatabaseOperation getSetUpOperation() throws Exception
    {
        dbConnection = DriverManager.getConnection("jdbc:hsqldb:mem:tests", "sa", "");
        createTables();
        return DatabaseOperation.REFRESH;
    }

    private void createTables() throws Exception {
        PreparedStatement statement = dbConnection
                .prepareStatement("CREATE TABLE digidauthsessions ( "
                        + "id INTEGER IDENTITY NOT NULL PRIMARY KEY,"
                        + "request_token VARCHAR(50) NOT NULL,"
                        + "response_token VARCHAR(50) NOT NULL,"
                        + "relatienr VARCHAR(50) NOT NULL,"
                        + "digidnameid VARCHAR(1000) NOT NULL" + ")");
        statement.execute();
        statement.close();
    }