exportdatebase.java

来自「在线考试功能」· Java 代码 · 共 48 行

JAVA
48
字号
package com.onlinestudy.domain;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

import java.io.File;

public class ExportDateBase {

	static Session session;

	public static void main(String[] args) {
	Configuration config = null;
	Transaction tx = null;

	try {
	config = new Configuration().configure(new File("src/hibernate.cfg.xml"));
	System.out.println("Creating tables...");
	SchemaExport schemaExport = new SchemaExport(config);
	schemaExport.create(true, true);
	System.out.println("Table created.");
	SessionFactory sessionFactory = config.buildSessionFactory();
	session = sessionFactory.openSession();
	tx = session.beginTransaction();
	tx.commit();

	} catch (HibernateException e) {
	e.printStackTrace();
	try {
	tx.rollback();
	} catch (HibernateException e1) {
	e1.printStackTrace();
	System.out.println("Table created failure");
	}
	} finally {

	}
	}


}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?