通过休眠连接到MS SQL [英] Connecting to MS sql through hibernate

查看:135
本文介绍了通过休眠连接到MS SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用java中的hibernate连接到MS SQl server 2005。我无法找到相同的jar和hibernate.cfg.xml文件。有人可以帮我解决这个问题。

Pascal Thivent ,使用任何一个驱动程序。对于JTDS,请使用以下配置。

 < hibernate-configuration> 
< session-factory>
< property name =connection.url> jdbc:jtds:sqlserver://XX.XX.XXX.XX:YYYY / DB-NAME< / property>
< property name =connection.driver_class> net.sourceforge.jtds.jdbc.Driver< / property>
< property name =connection.username>用户名< / property>
< property name =connection.password>密码< / property>
< property name =dialect> org.hibernate.dialect.SQLServerDialect< / property>



< / session-factory>
< / hibernate-configuration>

在使用Microsoft SQL JDBC Driver的情况下,

 <冬眠-结构> 
< session-factory>
< property name =connection.url> jdbc:microsoft:sqlserver://XX.XX.XXX.XX:YYYY / DB-NAME< / property>
< property name =connection.driver_class> com.microsoft.sqlserver.jdbc.SQLServerDriver< / property>
< property name =connection.username>用户名< / property>
< property name =connection.password>密码< / property>
< property name =dialect> org.hibernate.dialect.SQLServerDialect< / property>



< / session-factory>
< / hibernate-configuration>


I want to connect to MS SQl server 2005 using hibernate in java. i am unable to find the jars and the hibernate.cfg.xml file for the same. can someone help me with the same

解决方案

As mentioned by Pascal Thivent, use any one driver. In case of JTDS, use the following configuration.

<hibernate-configuration>
<session-factory>
    <property name="connection.url">jdbc:jtds:sqlserver://XX.XX.XXX.XX:YYYY/DB-NAME</property>
    <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
    <property name="connection.username">username</property>
    <property name="connection.password">password</property>
    <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
. 
.
.
</session-factory>
</hibernate-configuration>

And in case of Microsoft SQL JDBC Driver,

<hibernate-configuration>
<session-factory>
    <property name="connection.url">jdbc:microsoft:sqlserver://XX.XX.XXX.XX:YYYY/DB-NAME</property>
    <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    <property name="connection.username">username</property>
    <property name="connection.password">password</property>
    <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
. 
.
.
</session-factory>
</hibernate-configuration>

这篇关于通过休眠连接到MS SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆