Yes, SchemaExport is great !! but this tool can only create a schema for an existing database. My question is wheter SchemaExport can also create the actual database.
I'm creating the database manually at this time, like this:
Code:
try {
Configuration cfg = new Configuration();
DatabaseProperties dbprops = new DatabaseProperties(getDBDriver(),
getDBDialect(), name, getDBURL(), dataPath, getDBUser(), getDBPass(), getShowSql(),getInstanceName());
SessionFactory f = ( SessionFactory) this.getServerContext().getBean("asknowSessionFactory");
String query = "CREATE DATABASE "+name;
Session s = f.openSession();
Transaction tx = s.beginTransaction();
Connection conn = s.connection();
java.sql.Statement st;
st = conn.createStatement();
st.execute( query );
tx.commit();
s.close();
String url = dbprops.constructJDBCUrl();
cfg.setProperty("hibernate.dialect", this.getDBDialect());
cfg.setProperty("hibernate.connection.driver_class", this.getDBDriver()); //"net.sourceforge.jtds.jdbc.Driver");
cfg.setProperty("hibernate.connection.url", url ); //"jdbc:jtds:sqlserver://localhost:1433/Test");
cfg.setProperty("hibernate.connection.username", this.getDBUser()); //"sysdba");
cfg.setProperty("hibernate.connection.password", this.getDBPass()); //"masterkey");
cfg.addJar("xmls.jar");
SchemaExport se = new SchemaExport(cfg);
se.create(false, true);