Java &引用;未知的JDBC类型代码。。在.setTypeCode列中;(数据链路)
我正在使用DllUtils,并希望使用它将数据库模式生成为XML文件。有人知道怎么用吗?我正在使用SQL Server进行测试。我不确定如何从中获取数据源对象。 我正在阅读,我认为我的“model”名称有问题,但我不知道为了获取数据库对象,它应该是什么Java &引用;未知的JDBC类型代码。。在.setTypeCode列中;(数据链路),java,sql-server,apache,Java,Sql Server,Apache,我正在使用DllUtils,并希望使用它将数据库模式生成为XML文件。有人知道怎么用吗?我正在使用SQL Server进行测试。我不确定如何从中获取数据源对象。 我正在阅读,我认为我的“model”名称有问题,但我不知道为了获取数据库对象,它应该是什么 public class Main { public static void main(String[] args) { SQLServerDataSource ds = new SQLServerDataSource();
public class Main {
public static void main(String[] args) {
SQLServerDataSource ds = new SQLServerDataSource();
ds.setDescription("Felix testing program");
ds.setServerName("localhost");
ds.setPortNumber(1433);
ds.setUser("test");
ds.setPassword("1234");
ds.setDatabaseName("database");
try {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.naming.java.javaURLContextFactory");
System.setProperty(Context.URL_PKG_PREFIXES,
"org.apache.naming");
Hashtable<String, String> pdEnv = new Hashtable<String, String>();
pdEnv.put(Context.INITIAL_CONTEXT_FACTORY,"org.apache.naming.java.javaURLContextFactory");
pdEnv.put(Context.PROVIDER_URL, "jdbc:sqlserver://localhost:1433");
Context ctx = new InitialContext(pdEnv);
ctx.bind("jdbc:sqlserver", ds);
DataSource ds2 = (DataSource)ctx.lookup("jdbc:sqlserver");
Database db = readDatabase(ds2);
writeDatabaseToXML(db, "C:/Users/fcao/Documents/sample.xml");
readDatabaseFromXML("C:/Users/fcao/Documents/sample.xml");
} catch (NamingException e) {
e.printStackTrace();
}
}
public static Database readDatabaseFromXML(String fileName)
{
return new DatabaseIO().read(fileName);
}
public static void writeDatabaseToXML(Database db, String fileName)
{
new DatabaseIO().write(db, fileName);
}
public static Database readDatabase(DataSource dataSource)
{
Platform platform = PlatformFactory.createNewPlatformInstance(dataSource);
return platform.readModelFromDatabase("model");
}
public static void changeDatabase(DataSource dataSource,
Database targetModel,
boolean alterDb)
{
Platform platform = PlatformFactory.createNewPlatformInstance(dataSource);
if (alterDb)
{
platform.alterTables(targetModel, false);
}
else
{
platform.createTables(targetModel, true, false);
}
}
来自,java.lang.String)文档。如果我的数据库名称是“数据库”,那么该名称应该是什么
获取数据库
公共数据库getDatabase(连接,
字符串名称)
抛出SQLException从给定连接读取数据库模型。参数:connection-连接名称-
结果数据库的名称;当默认名称(默认名称)为
catalog)本身可能为空,但返回
数据库模型抛出:SQLException
readModelFromDatabase
数据库readModelFromDatabase(连接,
字符串名称)
抛出DatabaseOperationException从给定数据库所指向的实时数据库中读取数据库模型
连接正在指向。参数:connection-到
数据库名称-结果数据库的名称;当
需要默认名称(目录),其本身可能为空
虽然返回:数据库模型抛出:DatabaseOperationException
-如果在读取模型期间发生错误
我试图使我的代码保持最新,并且我已经尝试了几乎所有的方法来理解如何获得数据源对象,这样我就可以获得一个数据库对象,使用DllUtils示例中的writeDatabaseToXML方法来生成xml文件。如果有人能让代码正常工作,那就太棒了!我们真的需要在ddlUtils框架中构建几个部分。。!我试图使我的代码保持最新,并且我已经尝试了几乎所有的方法来理解如何获得数据源对象,这样我就可以获得一个数据库对象,使用DllUtils示例中的writeDatabaseToXML方法来生成xml文件。如果有人能让代码正常工作,那就太棒了!我们真的需要在ddlUtils框架中构建几个部分。。!
public static Database readDatabase(DataSource dataSource)
{
Platform platform = PlatformFactory.createNewPlatformInstance(dataSource);
Database db = null;
try {
db = platform.getModelReader().getDatabase(dataSource.getConnection(), "database");
} catch (Exception e) {
e.printStackTrace();
}
return db;
}