Configuration of Hibernate connection to various databases 1. MySql connection configuration hibernate connection settings for MySql database, in the hibernate. cfg. xml file hibernate-configurationsession-factory! -- Configure Attributes --! -True indicates that the SQL statement sent by Hibernate to the database is displayed -- propertynameshow_sq
Configuration of Hibernate connection to various databases 1. MySql connection configuration hibernate connection settings for MySql database, in the hibernate. cfg. xml file hibernate-configuration session-factory! -- Configure Attributes --! -True indicates that the SQL statement sent by Hibernate to the database is displayed -- property name = show_sq
Configure the connection between Hibernate and various databases
1. MySql connection Configuration
MySql database hibernate connection settings, in the hibernate. cfg. xml file
True
Net. sf. hibernate. dialect. MySQLDialect
50
30
Com. mysql. jdbc. Driver
Jdbc: mysql: // localhost/dbname?
CharacterEncoding = gb2312
Root
Root
The Driver class used above is com. mysql. jdbc. Driver. You need to package the connector jar package (eg. MySql-connector-java-
Dbname indicates the database name.
5.0.4-bin. jar) is added to classpath.
2. SQL Server connection Configuration
Hibernate of the SQL Server database is configured in the configuration file.
Connection Section
Net. sourceforge. jtds. jdbc. Driver
Name = "connection. url"> jdbc: jtds: sqlserver: // localhost: 1433; DatabaseName = dbname
Sa
The driver class in the above example uses the jtds driver class, so the reader needs to add the jtds jar package (eg. jtds-1.2.jar) to classpath
3. Oracle connection Configuration
Hibernate of the fiddler database is configured in the configuration file.
Connection Section
Oracle. jdbc. driver. OracleDriver
Jdbc: oracle: thin: @ localhost: 1521: dbname
Test
Test
In the above example, the driver class is oracle. jdbc. driver. OracleDriver. developers need to add the relevant jar package (ojdbc14.jar) to classpath.
4. DB2 connection Configuration
Hibernate of the DB2 database is configured in the configuration file.
Connection Section
Com. ibm. db2.jdbc. app. DB2Driver
Name = "connection. url"> jdbc: db2: // localhost: 5000/sample// Sample indicates the database name.
Admin
In the above example, the driver class is com. ibm. db2.jdbc. app. DB2Driver. developers need to add the relevant jar package (db2jcc. jar) to classpath.
5. sybase connection Configuration
Hibernate of the sybase Database is configured in the configuration file.
Connection Section
Com. sybase. jdbc. SybDrive
Name = "connection. url"> jdbc: sybase: Tds: localhost: 5007/myDB; // MyDB indicates the Database Name
Userid
User_password
In the above example, the driver class is com. sybase. jdbc. SybDrive. developers need to add the relevant jar package (jconn3.jar) to classpath.
6. informix connection Configuration
Hibernate of the informix database is configured in the configuration file.
Connection Section
Com. informix. jdbc. IfxDrive
Name = "connection. url"> jdbc: informix-sqli: // 123.45.67.89: 1533/myDB: INFORMIXSERVER = myserver; // MyDB indicates the Database Name
Testuser
Testpassword
In the above example, the driver class is com. informix. jdbc. IfxDrive. developers need to add the relevant jar package (ifxjdbc. jar) to classpath.
7. PostgreSQL connection Configuration
The hibernate of the PostpreSQL database is configured in the configuration file.
Connection Section
Org. postgresql. Driver
Name = "connection. url"> jdbc: postgresql: // localhost/myDB; // MyDB indicates the Database Name
Myuser
Mypassword
The driver class used in the previous example is com. informix. jdbc. IfxDrive, and developers need to add the relevant jar package (postgresql-8.1-405.jdbc3) to classpath.
8. access Connection Configuration
Hibernate of the access database is configured in the configuration file.
Connection Section
Sun. jdbc. odbc. JdbcOdbcDriver
Name = "connection. url "> jdbc: odbc: Driver = {MicroSoft .. access .. driver (*. mdb)}; DBQ = "+ application. getRealPath ("/Data/ReportDemo. mdb "); // MyDB indicates the Database Name
Myuser
Mypassword
The access Database driver is sun. jdbc. odbc. JdbcOdbcDriver or com. hxtt. SQL. access. AccessDriver.
Jar package: Access_JDBC30.jar address: http://www.hxtt.com/access.zip
Access dialect package (hibernate. jar) Address: http://www.hxtt.com/test/hibernate.zip