配置数据源两种方法

1、在hibernate.properties中指定

/*显示实际操作数据库时的SQL */

hibernate.properties hibernate.show_sql = true

/* SQL方言,这边设定的是MySQL */

hibernate.dialect = net.sf.hibernate.dialect.MySQLDialect

  /*JDBC驱动程序 */

hibernate.connection.driver_class = com.mysql.jdbc.Driver

/* JDBC URL -->

hibernate.connection.url = jdbc:mysql://localhost/HibernateTest

/* 数据库使用者 */

hibernate.connection.username = caterpillar

/* 数据库密码 */

hibernate.connection.password = 123456

2、在hibernate.cfg.xml中指定

<hibernate-configuration>

    <session-factory>

        /* 显示实际操作数据库时的SQL*/

        <property name="show_sql">true</property>

        /*SQL方言,这边设定的是MySQL*/

        <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

        /* JDBC驱动程序 */

        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

        /* JDBC URL*/

        <property name="connection.url">jdbc:mysql://localhost/HibernateTest</property>

        /* 数据库使用者*/

        <property name="connection.username">caterpillar</property>

        /* 数据库密码*/

        <property name="connection.password">123456</property>

        /*对象与数据库表格映像文件*/

        <mapping resource="User.hbm.xml"/>

    </session-factory>

</hibernate-configuration>

需要注意的是SQLServer2000与SQLServer2005的驱动程序及URL格式的不同

SQLServer2000:

driver:com.microsoft.jdbc.sqlserver.SQLServerDriver

url:jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Example

SQLServer2005

driver:com.microsoft.sqlserver.jdbc.SQLServerDriver

url:jdbc:sqlserver://127.0.0.1:1433;DatabaseName=Example

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值