This is how to connect to MSQSQL Microsoft SQL Server using Java and Hibernate application?

(Last Updated On: November 24, 2010)

This is  how to connect to MSQSQL Microsoft SQL Server using Java and Hibernate application?

Using Java Hibernate to connect to Microsoft SQL Server? Here is the world famous unknown gotcha

For those that don’t know, and you’re pulling out your hair? Ensure you do and check for:

on sql server  configuration manager, ensure services and connections
under TCPIP properties are enabled, as well as both dynamic TCP and
TCP ports are included of 1433 (listening port). this is for IP1, IP2,
and IPall


Ensure you use the JDTS JDBC connector, not the Microsoft one as it has many bugs. Get the right connector at:


Also, here is a sample of what your hibernate.cfg.xml you should look like as well:



<!–<session-factory name=”java:comp/hibernate/SessionFactory”>

<session-factory name=”java:hibernate/SessionFactory”>  –>

<!– Database connection settings –>

<property name=”connection.driver_class”>net.sourceforge.jtds.jdbc.Driver</property>




<!– JDBC connection pool (use the built-in) –>

<property name=”connection.pool_size”>1</property>

<!– SQL dialect –>

<property name=”dialect”>org.hibernate.dialect.SQLServerDialect</property>

<!– Enable Hibernate’s automatic session context management –>

<property name=”current_session_context_class”>thread</property>

<!– Disable the second-level cache  –>

<property name=”cache.provider_class”>org.hibernate.cache.NoCacheProvider</property>

<!– Echo all executed SQL to stdout –>


<!– Drop and re-create the database schema on startup –>

<!–<property name=”hbm2ddl.auto”>create</property> –>

<property name=”hbm2ddl.auto”>update</property>

Note you may need to use the host server’s IP address instead of localhost in case the server is remote. i.e.

These tips should help you out to easily connect to SQL Server using Java’s Hibernate framework.

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Subscribe For Latest Updates

Sign up to best of business news, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.


Check NEW site on stock forex and ETF analysis and automation

Scroll to Top