0

我正在使用sql server 2008 r2 sql express。 我通常连接到我的SQL是这样的: enter image description here无法连接jdbc到sql server 2008 r2

现在我想从我的eclipse连接到sql server 2008 r2。

我搜索谷歌,我发现我必须下载一个jar文件,我做了,我把它添加到我的项目在日食。

我的代码是

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
      String connectionUrl = "jdbc:sqlserver://localhost:1433;" 
        + "databaseName=DATABASE;user=User-PC\\User;password=;"; 

说实话:我不知道我是否应该把localhostsqlexpress,我不知道密码,因为我要你的图像或我只是用它是空的。

的例外是:

The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.". 

我在SQL配置启用TCP/IP

请帮我

+0

您使用的是root用户? – 2013-04-28 07:01:47

+0

yes,................ – 2013-04-28 07:12:29

+0

'我读过根用户不能在JDBC中使用,所以首先你必须创建一个新的'Login'在你的sql server中,然后创建新的'User'。之后,请尝试再次连接并告诉我发生了什么。 – 2013-04-28 07:14:12

回答

0

enter image description here

当你创建一个新用户,你必须设置该用户的登录名,请检查图像,并按彩色按钮,并选择您的登录。

后,改变你的字符串URL连接到这一点:

Class.forName(DB_DRIVER_NAME); 
      String connectionString = "jdbc:sqlserver://" + DB_SERVER 
        + ";databaseName=" + DB_NAME + ";user=" + DB_USER 
        + ";password=" + DB_PASSWORD; 
+0

你愿意等一下,我正在尝试 – 2013-04-28 15:51:43

+0

非常感谢。有用 :) – 2013-04-28 15:54:41