java 无法使用 JDBC 连接到 Sql Server 数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29316729/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 15:02:41  来源:igfitidea点击:

Can't connect to Sql Server database using JDBC

javasql-servernetbeans

提问by stijn.aerts

I'm trying to make a connection to an already existing database in SQL Server 2012n with Netbeans 8.

我正在尝试使用 Netbeans 8 连接到 SQL Server 2012n 中现有的数据库。

Using the connection wizard I select Sql Server 2012 and enter the credentials and fields.

使用连接向导,我选择 Sql Server 2012 并输入凭据和字段。

However I get the message that a connection cannot be established.

但是我收到无法建立连接的消息。

You can see screenshots of the entered fields:

您可以看到输入字段的屏幕截图:

Sql Server

数据库服务器

Netbeans connection wizard

Netbeans 连接向导

I also tried using "localhost" instead of "STIJN" this didn't work. I also tried with the default port "1433". Also didn't worked, however what port should this be? Where can I see what port I'm using? Maybe the error lies in the port, otherwise I wouldn't know where I made a mistake.

我还尝试使用“localhost”而不是“STIJN”,但这不起作用。我还尝试使用默认端口“1433”。也没有用,但是这应该是什么端口?我在哪里可以看到我正在使用的端口?也许错误出在端口上,否则我不知道我在哪里犯了错误。

回答by stijn.aerts

Go to your SQL Server configuration manager -> SQL server network configuration -> protocols for SQLEXPRESS -> TCP/IP (double click on it for properties).

转到您的 SQL Server 配置管理器 -> SQL 服务器网络配置 -> SQLEXPRESS 的协议 -> TCP/IP(双击它的属性)。

On protocol page set enabled to Yes. On IP Addresses page, scroll to bottom. TCP Dynamic Ports: 54629 TCP Port: 1433 Apply and ok.

在协议页面设置启用为是。在 IP 地址页面上,滚动到底部。TCP 动态端口:54629 TCP 端口:1433 应用并确定。

Make a connection with: Host: localhost Port: 1433 Your credentials Instance field = blank.

与以下对象建立连接:主机:本地主机端口:1433 您的凭据实例字段 = 空白。

This should work.

这应该有效。