读取Hibernate属性文件
把连接数据库的信息放入Hibernate属性文件中,如用户名、密码,然后读取,大家给个例子啊
------解决方案--------------------<?xml version='1.0' encoding='GB18030'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">sa1</property>
<property name="connection.url">jdbc:jtds:sqlserver://localhost</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="myeclipse.connection.profile">net.sourceforge.jtds.jdbc.Driver</property>
<property name="connection.password"></property>
<property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
------解决方案--------------------以连接SQL Server数据库为例:
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.connection.driver_class=com.microsoft.jdbc.sqlserver.SQLServerDriver
hibernate.connection.url=jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=数据库名
hibernate.connection.username=用户名
hibernate.connection.password=密码
...
建议采用xml格式的配置文件。xml配置文件可以直接对映射文件进行配置,由Hibernate自动加载,而properties文件则必须在程序中通过编码加载映射文件。
------解决方案--------------------<?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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">dccuser</property>
<property name="connection.url">
jdbc:oracle:thin:@127.0.0.1:1521:ora9i
</property>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<property name="myeclipse.connection.profile">用户名</property>
<property name="connection.password">密码</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="show_sql">true</property>
<mapping resource="com/hibernate/model/Deptinfo.hbm.xml" />
</session-factory>
</hibernate-configuration>