毕业设计做完后,兴高采烈的把电脑重装系统了,由于鄙人习惯在重装系统之前手动卸载一部分软件……mysql没能幸免……而且我还手欠的勾选了:删除“连同本地数据库”。
这两天复习项目的时候……傻眼了,才想起来数据库没了……
解决前提:
(1)建立domain对象(pojo)
(2)创建domain对象和数据库的映射关系文件eg:User.hbm.xml
(3)创建hibernate配置文件 hibernate.cfg.xml(配置数据源)
准备好以上三部分后(幸好项目没删……domain、配置文件等都完好):
编写生成数据库的工具类:ExportDB
import
org.hibernate.cfg.Configuration;
import
org.hibernate.tool.hbm2ddl.SchemaExport;
public class ExportDB{
public static void main(String []args){
Configuration cfg = new Configuration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create(true,true);
}
}
运行下即可啦~~
在hibernate的权威指南的第二十章可以找到这个工具类的介绍和使用方法: