hibernate配置连接sqlsever2008数据库

<?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">
<hibernate-configuration>
    <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
    <property name="hibernate.connection.username">sa</property>
    <property name="hibernate.connection.password">sa123</property>
    <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> 
    <property name="hibernate.connection.url">jdbc:sqlserver://127.0.0.1:1433;database=hibernate</property>
    <property name="hibernate.hbm2ddl.auto">update</property>
    <property name="hibernate.format_sql">true</property>
    <property name="hibernate.show_sql">true</property>
   <mapping resource="hibernate/test/pojo/Person.hbm.xml"/><!--如果仅仅使用hibernate需要配置映射文件资源-->
    </session-factory>
</hibernate-configuration>

根据hibernate的properties 配置数据库实例文件来看。

## Microsoft Driver (not recommended!)
#hibernate.connection.driver_class com.microsoft.jdbc.sqlserver.SQLServerDriver
#hibernate.connection.url jdbc:microsoft:sqlserver://1E1;DatabaseName=test;SelectMethod=cursor
## The New Microsoft Driver 
#hibernate.connection.driver_class com.microsoft.sqlserver.jdbc.SQLServerDriver
#hibernate.connection.url jdbc:sqlserver://localhost

第一种方式不被推荐。所以我尝试用第二种方式。结果报错了。错误如下,error1.

Error1
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
第二种方式:按照实例上说的没有 数据库的说明啊。
<property name="hibernate.connection.url">jdbc:sqlserver://127.0.0.1:1433/hibernate</property>
第一种方式:结果成功了。问题到底出在哪里呢???
<property name="hibernate.connection.url">jdbc:sqlserver://127.0.0.1:1433;database=hibernate</property>

我想问一下hibernate推荐的连接sqlsever数据库的方式到底是啥呢?

转载于:https://my.oschina.net/u/2308739/blog/405227

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值