Hi all,
I've just found DdlUtils and I'm quite impressed by this package. I'm
running into a bit of trouble trying to export schema from MSSQL
databases, though. Here's a class I'm using to test out DdlUtils (I'm
omitting the imports for the sake of brevity)
public class DdlUtilTest {
public static void main(String[] args) throws SQLException {
JtdsDataSource ds = new JtdsDataSource();
ds.setUser("sa");
ds.setPassword("xxxxx");
ds.setServerName("x.x.x.x");
ds.setDatabaseName("MyDbName");
Connection conn = ds.getConnection();
DatabaseMetaData meta = conn.getMetaData();
Platform p = PlatformFactory.createNewPlatformInstance(ds);
String filename = "src\\schema\\MyDbName-schema.xml";
new DatabaseIO().write(p.readModelFromDatabase("MyDbName"), filename);
}
}
This works perfectly for some databases, but throws seemingly random
exceptions for others. For example, running it against "MyDbName"
properly generates src\schema\MyDbName-schema.xml, which contains the
correct schema. However, trying to run it against "MySecondDb" throws
this exception:
Exception in thread "main" org.apache.ddlutils.DynaSqlException:
java.sql.SQLException: Invalid column name 'Zip'.
at
org.apache.ddlutils.platform.PlatformImplBase.readModelFromDatabase(PlatformImplBase.java:1706)
at
org.apache.ddlutils.platform.PlatformImplBase.readModelFromDatabase(PlatformImplBase.java:1684)
at com.mycompany.test.ddlutiltest.DdlUtilTest.main(DdlUtilTest.java:69)
Trying to run it against "YetAnotherDb" throws this exception:
Exception in thread "main" org.apache.ddlutils.DynaSqlException:
java.sql.SQLException: Incorrect syntax near the keyword 'Primary'.
at
org.apache.ddlutils.platform.PlatformImplBase.readModelFromDatabase(PlatformImplBase.java:1706)
at
org.apache.ddlutils.platform.PlatformImplBase.readModelFromDatabase(PlatformImplBase.java:1684)
at com.mycompany.test.ddlutiltest.DdlUtilTest.main(DdlUtilTest.java:69)
In both of these cases the exception is being thrown from this line:
new DatabaseIO().write(p.readModelFromDatabase("MyDbName"),
filename);
I've tried several of the different signatures for
readModelFromDatabase() and I wind up with the same exceptions no matter
what I pass to it. Has anyone experienced similar issues? Am I using one
of the DdlUtils methods incorrectly, or are the exceptions being thrown
due to some problem with the database server?
Thanks,
Shaun