This week's book giveaway is in the JDBC forum.
We're giving away four copies of Make it so: Java DB Connections & Transactions and have Marcho Behler on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes TCP/IP connection to the host localhost, port 1433 has failed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "TCP/IP connection to the host localhost, port 1433 has failed" Watch "TCP/IP connection to the host localhost, port 1433 has failed" New topic

TCP/IP connection to the host localhost, port 1433 has failed

Babugouda patil
Ranch Hand

Joined: Mar 13, 2011
Posts: 35


I am new to Hibernate. I am not able to make connection. Below I placed all code which I have used to make connection to SQL Server 2008 but it's giving below error. Please check my configuration file as well and correct me.

Console Error:
Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.jdbc.ConnectionManager.openConnection(
at org.hibernate.jdbc.ConnectionManager.getConnection(
at org.hibernate.jdbc.JDBCContext.connection(
at org.hibernate.transaction.JDBCTransaction.begin(
at org.hibernate.impl.SessionImpl.beginTransaction(
at org.babu.hibenate.HibernateTest.main(
Caused by: The TCP/IP connection to the host localhost, port 1433 has failed. Error: Connection refused: connect. Please verify the connection properties and check that a SQL Server instance is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(
at org.hibernate.jdbc.ConnectionManager.openConnection(
... 5 more

Below is code:

hibernate.cfg.xml file configuration:



<!-- Database connection settings -->
<property name="connection.driver_class"></property>
<property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName=JDBC;</property>
<property name="connection.username">BABU-GOUDA/hp</property>
<property name="connection.password"></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>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="">create</property>

<!-- Names the annotated entity class -->
<mapping class="org.babu.dto.UserDetails"/>



and class is:

Please check and tell me where went wrong and what's the problem.

SCJP 1.6 91%
Take certification exam as a point of learning not just for certificate
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

Observing the Stack Trace, I believe, your application is unable to connect to the MS-SQLServer. Please check if TCP connections can be made with the MS-SQLServer at the given port.

Not many get the right opportunity !
I agree. Here's the link:
subject: TCP/IP connection to the host localhost, port 1433 has failed
It's not a secret anymore!