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
4 Answers
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>
-
Doesn't mention the name of file to save the above code into. – user275801 Dec 05 '19 at 04:09
All you need is the driver class and proper dialect. See http://msdn.microsoft.com/en-us/library/ms378749.aspx
If you have the driver, then (at a minimum) you need to specify the connection properties: http://www.roseindia.net/hibernate/firstexample.shtml
The proper dialect appears to be: org.hibernate.dialect.SQLServerDialect

- 3,177
- 4
- 22
- 26
I am unable to find the jars.
Get a JDBC driver for SQL Server 2005 from Microsoft or use the open source alternative jTDS.
and the hibernate.cfg.xml file for the same
The dialect for SQL Server 2005 is org.hibernate.dialect.SQLServerDialect
.
The other params (like the driver class name, the jdbc URL) will depend on the driver you choose. Refer to the respective documentation.

- 562,542
- 136
- 1,062
- 1,124
I also faced and after lot of tries i found solution and its working fine for me
You can create connection using JNDI connection string also.
In ApplicationContext.xml or applicationContext-resources.xml
<jee:jndi-lookup id="dataSource" lookup-on-startup="true" resource-ref="true" jndi-name="jdbc/resourcename"/>
In Apache Context.xml
<Resource name="jdbc/resourcename" auth="Container" type="javax.sql.DataSource"
username=username password=password driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://localhost:1433;databaseName=dbname />
Add hibernate dialect in persistence.xml or hibernate.cfg.xml
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
Now just build your code and run on Apache server.

- 378
- 1
- 4
- 16