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.  [ 2 posts ] 
Author Message
 Post subject: How to create database with hibernate programmatically ??
PostPosted: Sat Jun 09, 2007 6:17 am 
Newbie

Joined: Thu May 31, 2007 8:28 am
Posts: 3
Location: INDIA
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate ver 3.1:

No Mapping docs-have to do it in coding ony!! :





Oracle/MySQL


Hi , I need to create database programmatically without using any mapping files/config files...
Do reply at [email protected]

Thanks...





Read this: http://hibernate.org/42.html



Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 1:53 am 
Newbie

Joined: Thu May 31, 2007 8:28 am
Posts: 3
Location: INDIA
Here we go,


public void CreateDB(String dbname) throws SQLException{
try{
System.out.println("INSIDE CREATEDB()...");
org.hibernate.connection.DriverManagerConnectionProvider cn=new org.hibernate.connection.DriverManagerConnectionProvider();
Properties p=new Properties();
//p.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/db1");
p.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect");
p.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
p.setProperty("hibernate.connection.username","root");
p.setProperty("hibernate.connection.password","root");
p.setProperty("hibernate.connection.url","jdbc:mysql://localhost:3306/temp");
p.setProperty("hibernate.order_updates", "true");
p.setProperty("hibernate.show_sql", "true");
p.setProperty("hibernate.format_sql", "true");
p.setProperty("hibernate.generate_statistics", "true");
p.setProperty("hibernate.use_sql_comments", "true");
p.setProperty("hibernate.connection.autocommit", "true");
cn.configure(p);
cn.getConnection().setCatalog("db1");
String sql="CREATE DATABASE IF NOT EXISTS "+dbname;
System.out.println("Executing..."+sql);
cn.getConnection().createStatement().execute(sql);
System.out.println("Execution Completed!!");
cn=null;
p=null;
}catch(Exception e){
System.err.println("Error in CreateDB()!!");
e.printStackTrace();
}
}


Nisarg Panchal

[email protected]
Gateway Techno Labs Pvt Ltd


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.