连接Oracle数据库的Hibernate配置文件

WBOY
Release: 2016-06-07 17:07:31
Original
1124 people have browsed it

连接Oracle数据库的Hibernate配置文件连接Oracle的Hibernate配置文件有两种格式,一种是xml格式的,另一种是Java属性文件格式的。

连接Oracle数据库的Hibernate配置文件
连接Oracle的Hibernate配置文件有两种格式,一种是xml格式的,另一种是Java属性文件格式的。下面分别给出这两种格式配置文件的代码。
1.xml格式的配置文件
下面将给出连接本地Oracle服务器上的db_database02数据库时Hibernate配置文件hibernate.cfg.xml的代码。

例程2-5:光盘\mr\02\sl\05\hibernate.cfg.xml

/P>

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

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

oracle.jdbc.driver.OracleDriver

jdbc:oracle:thin:@localhost:1521:db_database02

SYSTEM

SYSTEM

org.hibernate.dialect.Oracle9Dialect

true

在上面的代码中,“localhost”代表本地Oracle服务器,如果想连接其他服务器可以修改为要连接的Oracle服务器的名称; “db_database02”为要连接的数据库名称;“SYSTEM”为登录用户名;“SYSTEM”表示用户密码; “UserForm.hbm.xml”为持久化类对应的映射文件名称。

2.Java属性文件格式的配置文件
下面将给出连接本地Oracle服务器上的db_database02数据库时Hibernate配置文件hibernate.properties的代码。

例程2-6:光盘\mr\02\sl\06\hibernate.properties

#指定连接数据库使用的SQL方言#

hibernate.dialect=org.hibernate.dialect.MySQLDialect

#指定连接数据库的驱动程序#

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

#指定连接数据库的URL#

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

#指定连接数据库的用户名#

hibernate.connection.username=SYSTEM

#指定连接数据库的密码#

hibernate.connection.password=SYSTEM

#指定在执行程序时,是否在控制台上输出SQL语句#

hibernate.show_sql=true

在上面的代码中,“localhost”代表本地Oracle服务器,如果想连接其他服务器可以修改为要连接的Oracle服务器的名称;“db_database02”为要连接的数据库名称;“SYSTEM”为登录用户名;“SYSTEM”表示用户密码。

说明:在Hibernate包的etc目录下附带了一个用于连接各种关系数据库配置代码的hibernate.properties文件,读者可以根据该文件写出连接其他数据库的配置文件。

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!