简体   繁体   English

连接JDBC SQL Server错误

[英]Connection JDBC SQL Server Error

I've tryed to create a connection with a Microsoft SQl Server 2008 database through JDBC on Eclipse SDK. 我尝试通过Eclipse SDK上的JDBC创建与Microsoft SQl Server 2008数据库的连接。 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. 我从微软下载了JDBC驱动程序并安装了它,然后我在我的系统环境变量CLASSPATH中添加了sqljdbc4.jar文件的路径。 After icluding in the Eclipse project the jar file I've tryed to create the connection using: 在Eclipse项目中包含jar文件后,我尝试使用以下命令创建连接:

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. com.microsoft.sqlserver.jdbc.SQLServerException:主机localhost,端口1433上的TCP / IP连接失败。 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. 错误:“连接被拒绝:连接。验证连接属性并确保主机上正在运行SQL Server实例,并且正在接受端口上的TCP / IP连接。请确保没有防火墙阻止端口上的连接。

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. 我正在研究JRE 1.6,所以sqljdbc4应该工作,我已经创建了一个有效的ODBC,所以服务器正在响应,错误应该在java命令或JDBC安装中。

Can anyone help me? 谁能帮我?

At the risk of stating the obvious, this looks to me as if TCP connections haven't been enabled on SQL Server. 冒着明显的风险,这看起来好像在SQL Server上没有启用TCP连接。 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. 有MSDN上的一篇文章在这里 ,说明如何启用SQL 2005/2008 TCP协议。

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 如果您正在使用eclipse,则无需将jar添加到CLASSPATH变量中,只需将其添加到项目库中即可在运行时使用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM