把连接数据库的信息放入Hibernate属性文件中,如用户名、密码,然后读取,大家给个例子啊

解决方案 »

  1.   

    hibernate.properties你如果有这个文件,hibernate会自己去找的
      

  2.   

    <?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>
      

  3.   

    难道hibernate.cfg.xml里面没有配置?
      

  4.   

    2楼那是Sping的xml文件,再把这些数据抽出来放到配置文件中,再读取是怎么搞的??
      

  5.   

    建议lz去网上看看hibernate连接的例子。很多也很全。
      

  6.   

    以连接SQL Server数据库为例:
    hibernate.dialect=org.hibernate.dialect.SQLServerDialecthibernate.connection.driver_class=com.microsoft.jdbc.sqlserver.SQLServerDriverhibernate.connection.url=jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=数据库名hibernate.connection.username=用户名hibernate.connection.password=密码...
    建议采用xml格式的配置文件。xml配置文件可以直接对映射文件进行配置,由Hibernate自动加载,而properties文件则必须在程序中通过编码加载映射文件。
      

  7.   

    <?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>
      

  8.   

    以连接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=密码
    ....
    我想知道具体是怎么来读取这些配置,给点代码啊
      

  9.   

        <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="location"><value>classpath:hibernate.properties</value></property>
        </bean>