I’ve got the following java code, which is giving the error below:
import java.io.File;
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.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
public class export {
public static void main(String[] args) throws Exception {
// database connection
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection jdbcConnection = DriverManager.getConnection(
"jdbc:jtds:sqlserver://localhost:1433/exampleDB", "sa", "vista1");
IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
// full database export
IDataSet fullDataSet = connection.createDataSet();
FlatXmlDataSet.write(fullDataSet, new FileOutputStream("full.xml"));
}
}
Error:
$ java export
Exception in thread "main" java.lang.NoClassDefFoundError: org/dbunit/database/IDatabaseConnection
Caused by: java.lang.ClassNotFoundException: org.dbunit.database.IDatabaseConnection
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: export. Program will exit.
The name of the java file being compiled is export.java and the name of the compiled file is export.class, and I’ve put the dbunit-2.4.8.jar and jtds-1.2.5.jar files in to the same folder as export.java and export.class; and I’m compiling export.java with the following cmd:
$ javac -cp "dbunit-2.4.8.jar;jtds-1.2.5.jar" export.java
Any idea what I’m doing wrong?
I’m using this on an oracle database and it works fine ^^