From an older post i found the following code. This works but needs a default db e.g. test to connect. Is there a way to create db without connecting to already present db?
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","admin");
p.setProperty("hibernate.connection.url","jdbc:mysql://localhost:3306/test");
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 "+ "db1";
System.out.println("Executing..."+sql);
cn.getConnection().createStatement().execute(sql);
System.out.println("Execution Completed!!");
cn=null;
|