Hi, all
How to make connection to database more dynamically using hibernate.
Example while my application running, I want to change connection to other server and database name but structure database is still same.
I using jdbc I commonly using code like this
public static void getConnection(){
try { Class.forName("com.mysql.jdbc.Driver").newInstance() ;
con=null;
con=DriverManager.getConnection("jdbc:mysql://"+MainMenu.serverName+
"/" +
MainMenu.dbName + "?user=root&password=root");
} catch (Exception e){
System.out.println(e);
}
}
Then if connection to database using file .properties or .xml like this how to make ?
File jdbc.properties
jdbc.username=root
jdbc.password=root
jdbc.url=jdbc:mysql://localhost/mydb1
jdbc.driver=com.mysql.jdbc.Driver
or file hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD
3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property
name="connection.url">jdbc:mysql://localhost/mydb1</property>
<property name="connection.username">root</property>
<property
name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property
name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.password"></property>
<property
name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
thanks a lot.