Apache DdlUtils入门
2016-06-02 16:35
316 查看
Introduction
DdlUtils is a small, easy-to-use component for working with Database Definition (DDL) files. These are XML files that contain the definition of a database schema, e.g. tables and columns. These files can be fed into DdlUtils via its Ant task or programmatically in order to create the corresponding database or alter it so that it corresponds to the DDL. Likewise, DdlUtils can generate a DDL file for an existing database.DdlUtils既可以根据定义数据库schema的XML文件(DDL文件)创建或者修改数据库,也可以为现有的数据库生成一个DDL文件。
简单来讲,DdlUtils既是一个library,也是操作数据库schema的Ant tasks。它可以创建和删除数据库,创建、修改和删除表。此外,还可以将XML中定义的数据插入数据库,或者将数据库中的数据读到XML文件中。
DdlUtils追求数据库独立性。schema文件是Turbine XML格式。这种XML格式文件同样用在 Torque 和 OJB 中。
DdlUtils APIs
DdlUtils的核心是定义在org.apache.ddlutils.model中的数据库model,它由表示数据库的schema的各种类组成。Reading from XML
import java.util.ArrayList; import java.util.Iterator; import javax.sql.DataSource; import org.apache.commons.beanutils.DynaBean; import org.apache.ddlutils.Platform; import org.apache.ddlutils.PlatformFactory; import org.apache.ddlutils.model.Database; import org.apache.ddlutils.model.Table; ... public void dumpBooks(DataSource dataSource, Database database) { Platform platform = PlatformFactory.createNewPlatformInstance(dataSource); ArrayList params = new ArrayList(); params.add("Some title"); Iterator it = platform.query(database, "select * from book where title = ?", params, new Table[] { database.findTable("book") }); while (it.hasNext()) { DynaBean book = (DynaBean)it.next(); System.out.println(book.get("title")); } }
View Code
Note: 以上只是样例APIs,仅供参考。
Reference
https://db.apache.org/ddlutils/api-usage.htmlhttps://db.apache.org/ddlutils/databases/mysql.html
相关文章推荐
- apache防盗链
- 使用apache benchmark(ab) 测试报错: apr_socket_recv: Connection timed out (110)
- 使用apache benchmark(ab) 测试报错: apr_socket_recv: Connection timed out (110)
- Log4j使用
- Mac下启动Apache配置
- Windows环境下,Apache,MySQL等服务以普通用户身份运行具体设置
- Web性能优化之Apache篇
- 安装最新版本的PHP或Apache中遇到的问题
- Dubbo消费端错误: ClassNotFoundException: org.apache.zookeeper.proto.WatcherEvent
- MQ消息队列系列(5)ActiviteMQ Getting Started Guide(apache官网翻译)
- apache-utf8中文问题
- apache 域名转发功能
- Apache常用配置项
- ClassNotFoundException:org.apache.commons.logging.LogFactory
- centos64-python27-mod_wsgi-apache2.4
- Mac OS下Web服务器配置
- apache支持中文域名绑定,apache支持中文域名绑定,教你怎样让apache支持中文域名绑定
- apache优化配置
- 远程服务器:PHP5.5+apache2.4+SQL SERVER2008开发环境配置
- Apache重启问题