`

根据hibernate.cfg.xml文件生成POJO数据库表的工具类

阅读更多
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
/**
* DESC-根据hibernate.cfg.xml配置文件和相应实体类及其.hbm.xml文件生成对应的数据库表
* 使用步骤:
* 1.建立hibernate.cfg.xml配置文件且在数据库url后面指定数据库名称jdbc:mysql://localhost/DB_NAME(该配置文件放在src根目录)
* 2.建立好相应的POJO类和对应的.hbm.xml文件(需要hibernate.cfg.xml中配置)
* 3.创建数据库:create database DB_NAME;
* 4.打开数据库:use DB_NAME;
* 5.手动执行此类
* @author Administrator
*
*/
public class ExportDB {
public static void main(String[] args) {
//读取hibernate.cfg.xml文件
Configuration cfg = new Configuration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);
}
}
分享到:
评论
3 楼 王添宝 2012-04-15  
我还以为是什么呢
2 楼 ydsakyclguozi 2009-05-21  
博主,很好很强大
1 楼 zjb10000 2009-03-17  
感谢,

相关推荐

Global site tag (gtag.js) - Google Analytics