-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: create database DDL
PostPosted: Tue Apr 12, 2005 10:24 am 
Beginner
Beginner

Joined: Tue Jan 18, 2005 9:37 am
Posts: 29
Location: The Netherlands
Hibernate version: 2.1.7

Name and version of the database you are using:
MS SQL SERVER 2000 and Firebird


Hi,
Can anyone tell me if it's possible to generate DDL for creating a database.
For example:
Code:
create database test


We want to use this because we want our application to create a database for each suite ( we create a suite for each customer).

Bas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 12, 2005 7:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
There is the SchemaExport Task. See the documentation.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 13, 2005 8:21 am 
Beginner
Beginner

Joined: Tue Jan 18, 2005 9:37 am
Posts: 29
Location: The Netherlands
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);
    


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.