Connect to the Hibernate configuration file of the Oracle database

Source: Internet
Author: User

Connect to the Hibernate configuration file of the Oracle database
The Hibernate configuration file connected to Oracle has two formats: xml and Java attribute file. The codes of the configuration files in these two formats are given below.

1. configuration file in xml format
The following provides the Hibernate configuration file hibernate. cfg. xml code for connecting to the db_database02 database on the local Oracle server.

Example 2-5: CD/mr/02/sl/05/hibernate. cfg. xml

<? Xml version = '1. 0' encoding = 'utf-8'?>

<! DOCTYPE hibernate-configuration

PUBLIC "-// Hibernate/Hibernate Configuration DTD // EN"

"Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<Hibernate-configuration>

<Session-factory>

<! -- Specify the driver used to connect to the database -->

<Property name = "connection. driver_class">

Oracle. jdbc. driver. OracleDriver

</Property>

<! -- Specify the path to connect to the database -->

<Property name = "connection. url">

Jdbc: oracle: thin: @ localhost: 1521: db_database02

</Property>

<! -- Specify the username used to connect to the database -->

<Property name = "connection. username"> SYSTEM </property>

<Property name = "connection. password"> SYSTEM </property> <! -- Specify the password to connect to the database -->

<! -- Specify the SQL dialect used by the database -->

<Property name = "dialect"> org. hibernate. dialect. Oracle9Dialect </property>

<! -- When the show_ SQL attribute is true, it indicates that the SQL statement is output on the console when the program is running. The default value is false. We recommend that you set it to true when debugging the program and change it to false before releasing the program, because the output SQL statement will affect the program running speed -->

<Property name = "show_ SQL"> true </property>

<Mapping resource = "UserForm. hbm. xml"/> <! -- Specify the persistent class ing file -->

</Session-factory>

</Hibernate-configuration>

In the code above, "localhost" indicates the local Oracle server. To connect to other servers, you can change it to the name of the Oracle server to be connected; "db_database02" indicates the name of the database to be connected; "SYSTEM" indicates the logon user name; "SYSTEM" indicates the user password; "UserForm. hbm. xml is the name of the ing file corresponding to the persistence class.

2. configuration file in Java attribute File Format
The Hibernate configuration file hibernate. properties code for connecting to the db_database02 database on the local Oracle server is provided below.

Example 2-6: CD/mr/02/sl/06/hibernate. properties

# Specify the SQL dialect used to connect to the database #

Hibernate. dialect = org. hibernate. dialect. MySQLDialect

# Specify the driver used to connect to the database #

Hibernate. connection. driver_class = oracle. jdbc. driver. OracleDriver

# Specify the URL to connect to the database #

Hibernate. connection. url = jdbc: oracle: thin: @ localhost: 1521: db_database02

# Specify the username used to connect to the database #

Hibernate. connection. username = SYSTEM

# Specify the database connection password #

Hibernate. connection. password = SYSTEM

# Specify whether to output SQL statements on the console during program execution #

Hibernate. show_ SQL = true

In the code above, "localhost" indicates the local Oracle server. To connect to other servers, you can change it to the name of the Oracle server to be connected; "db_database02" indicates the name of the database to be connected; "SYSTEM" indicates the logon user name, and "SYSTEM" indicates the user password.

Note: A Hibernate. properties file is attached to the etc directory of the hibernate package to connect to various Relational Database Configuration codes. You can write the configuration file for connecting to other databases based on this file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.