Automatic table creation:
Package mis. Business. util;
Import org. hibernate. cfg. configuration;
Import org. hibernate. tool. hbm2ddl. schemaexport;
Public class exportdb {
Public static void main (string [] ARGs ){
// Read the hibernate. cfg. xml file
Configuration CFG = new configuration (). Configure ();
Schemaexport export = new schemaexport (CFG );
Export. Create (True, true );
}
}
Connect to the sqlserver database:
<Hibernate-configuration>
<Session-factory>
<Property name = "connection. url"> JDBC: ODBC: Data Source Name </property>
<Property name = "connection. driver_class"> sun. JDBC. ODBC. jdbcodbcdriver </property>
<Property name = "hibernate. Connection. username"> logon name </property>
<Property name = "hibernate. Connection. Password"> password </property>
<Property name = "hibernate. dialect"> org. hibernate. dialect. sqlserverdialect </property>
<Property name = "hibernate. show_ SQL"> true </property>
<Property name = "hibernate. hbm2ddl. Auto"> Update </property>
</Session-factory>
</Hibernate-configuration>
Connect to the MySQL database:
<Hibernate-configuration>
<Session-factory>
<Property name = "hibernate. Connection. url"> JDBC: mysql: // localhost: 3306/database name </property>
<Property name = "hibernate. Connection. driver_class"> com. MySQL. JDBC. Driver </property>
<Property name = "hibernate. Connection. username"> logon name </property>
<Property name = "hibernate. Connection. Password"> password </property>
<Property name = "hibernate. dialect"> org. hibernate. dialect. mysqldialect </property>
<Property name = "hibernate. hbm2ddl. Auto"> Update </property>
<Property name = "hibernate. show_ SQL"> true </property>
</Session-factory>
</Hibernate-configuration>