0

I have a database in libreoffice Base (Debian) which I need to export the tables as an xml file. I have created a piece of Eclipse Java code which is as follows:

package NewDB;

import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.database.QueryDataSet;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.dbunit.dataset.DataSetException; 

public class ExtractTestDataSet {
public static void main(String[] args) throws Exception {
    // database connection
    Class driverClass = Class.forName("org.hsqldb.jdbcDriver");
    Connection jdbcConnection = DriverManager.getConnection "jdbc:hsqldb:/home/debian/Documents/database.odb", "sa", "");

    IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);

    // full database export
    IDataSet fullDataSet = connection.createDataSet();  
    FlatXmlDataSet.write(fullDataSet, new FileOutputStream("/home/debian/Documents/fulldataset.xml"));    

}
}

After looking at the DBunit pages and other various sites this code should be correct; the database is populated, the connections are valid, there are no warnings or errors in the code, however when the xml file is created the only content is as follows:

<?xml version='1.0' encoding='UTF-8'?>
<dataset/>

Does anyone have any ideas as to why the dataset is not being exported?

Thanks

xcc140
  • 13
  • 1
  • 4
  • Have you tried debug stepping into `connection.createDataSet()`? I can't spot anything wrong with your code, but perhaps stepping in will highlight something going wrong... – Jamey Apr 14 '14 at 10:48
  • Yes, I have tried stepping into it, and the connection is fine. I have even added a line to test the connection, and it gives no errors, along with an SQL warning line which gives no warnings. Thanks – xcc140 Apr 14 '14 at 11:01
  • Sorry, I explicitly meant the `createDataSet()` method. Perhaps you could turn on logging to trace and added the log to your question. It looks like DBUnit uses SLF4J. – Jamey Apr 14 '14 at 11:10
  • Actually it looks like that method does very little, so don't bother. Perhaps logging would help though... – Jamey Apr 14 '14 at 11:15
  • Also if you can get a breakpoint inside `FlatDtdWriter.write(IDataSet dataSet)` (which is I think the one you would be calling with your setup), then that's the meat of the code. In particular, following dataSet.getTableNames() should highlight the problem (since failing to find table names will give the output you're currently getting). Alternatively you could try feeding your table names into `createDataSet(tableNames)`. – Jamey Apr 14 '14 at 11:24
  • Sorry, I'm confused, I don't have `FlatDtdWriter.write(IDataSet dataSet)` Should I have it? – xcc140 Apr 14 '14 at 14:00
  • It's in the dbunit jar, but the best thing is to put a breakpoint at `FlatXmlDataSet.write(fullDataSet, new FileOutputStream("/home/debian/Documents/fulldataset.xml"));` and step in (you'll need to step out of the `new FileOutputStream("")` first). Also have you tried adding trace logging? – Jamey Apr 14 '14 at 14:09
  • I'll try the trace logging now, thanks – xcc140 Apr 14 '14 at 14:56
  • Turns out that the .odb database was connected to a different backend, explaining the blank dataset. Thanks for your help with this Jamey. – xcc140 Apr 22 '14 at 15:12
  • No worries, glad you found the problem. :D – Jamey Apr 22 '14 at 15:36

1 Answers1

0

Turns out that the .odb database was connected to a different backend, explaining the blank dataset.

xcc140
  • 13
  • 1
  • 4