package com.ztesoft.zsmart.saas.test; import java.util.HashMap; import java.util.Map; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; /** * 用于由Hibernate,OR映射文件,生成表 * @author Administrator * */ public class CreateDB { /** * 根据Hibernate配置文件、映射文件。在相应数据库中生成表。 */ public void createTable() { try { System.out.println("初始化数据开始......"); Map<String,String> map = new HashMap<String,String>(); map.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect"); map.put("hibernate.connection.driver_class", "com.mysql.jdbc.Driver"); map.put("hibernate.connection.url", "jdbc:mysql://localhost:3306/autocreate?useUnicode=true&characterEncoding=utf-8&&zeroDateTimeBehavior=convertToNull"); map.put("hibernate.connection.username", "admin"); map.put("hibernate.connection.password", "admin"); map.put("hibernate.show_sql", "true"); map.put("hibernate.hbm2ddl.auto", "create"); EntityManagerFactory emf = Persistence.createEntityManagerFactory("SAAS_PU",map); // /System.out.println(emf.getProperties()); emf.close(); System.out.println("初始化数据完成"); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { CreateDB db = new CreateDB(); db.createTable(); } }