0
votes

I've tryed to create a connection with a Microsoft SQl Server 2008 database through JDBC on Eclipse SDK. I've dowloaded JDBC driver from microsoft and I've installed it, then I've added at my System environment variables CLASSPATH the path of sqljdbc4.jar file. After icluding in the Eclipse project the jar file I've tryed to create the connection using:

String connectionUrl = "jdbc:sqlserver://localhost;integratedSecurity=true";
Connection con = DriverManager.getConnection(connectionUrl);

but it doesn't works, and launch me this exception:

com.microsoft.sqlserver.jdbc.SQLServerException: TCP/IP connection at host localhost, port 1433 failed. Error: "Connection refused: connect. Verify connection properties and make sure an instance of SQL Server is running on the host and is accepting TCP/IP connections at the port. Be sure no firewall blocks connections at the port.

I'm working on a JRE 1.6 so a sqljdbc4 should work, and I've created a working ODBC, so the server is responding, and the error should be in java command or JDBC installation.

Can anyone help me?

2
Have you tested telnet on port 1433? Or have you checked the database is up at all? Go to MS SQL Server Manager and check.mico

2 Answers

2
votes

At the risk of stating the obvious, this looks to me as if TCP connections haven't been enabled on SQL Server. You have to manually enable them, they don't come enabled by default.

There's an article on MSDN here which explains how to enable TCP protocols for SQL 2005/2008.

0
votes

Following are the quick trouble shooters:

  • Try to connect to your server using external front end.

  • Check if your firewall blocks the connection to the port

  • Check to see if server is really up.

A Suggestion :

If you are using eclipse , you don't need to add the jar into CLASSPATH variable , you can just add it in library of your project to make it available at runtime