gpt4 book ai didi

java - 与 MS SQL 服务器的连接错误

转载 作者:行者123 更新时间:2023-11-30 10:31:54 25 4
gpt4 key购买 nike

为什么我无法连接到 MS SQL 服务器?

依赖:

<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.5.jre8-preview</version>
</dependency>

Java 代码:

import java.sql.*;

try {
// Load the SQLServerDriver class, build the
// connection string, and get a connection

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://192.168.1.35\\SERVER-SQL;" +
"database=MainDataBase;" +
"user=user;" +
"password=rdthnb137";
Connection con = DriverManager.getConnection(connectionUrl);
System.out.println("Connected.");

// Create and execute an SQL statement that returns some data.

String SQL = "SELECT * from history";
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(SQL);

// Iterate through the data in the result set and display it.

while (rs.next()) {
System.out.println(rs.getString(1) + " " + rs.getString(2));
}
}
catch(Exception e) {
System.out.println(e.getMessage());
System.exit(0);
}

The connection to the host 192.168.1.35, named instance server-sql failed. Error : "java.net.SocketTimeoutException: Receive timed out". Verify the server and in stance names and check that no firewall is blocking UDP traffic to port 1434. F or SQL Server 2005 or later, verify that the SQL Server Browser Service is runni ng on the host.

Image of setup of port of a copy of the server

我是从本地机器连接的。防火墙已关闭。

已安装带有 Service Pack 4 更新的 MS SQL Server 2000。

当使用Connection con = DriverManager.getConnection( "jdbc:sqlserver://192.168.1.35;database=MainDataBase;", "user", "rdthnb137");错误:

22, 2017 1:49:58 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogi n WARNING: ConnectionID:1 ClientConnectionId: 6684e1dc-9950-4082-8fa9-73d5bf4b38b6 Server major version:8 is not supported by this driver. SQL Server version 8 is not supported by this driver. ClientConnectionId:6684e1d c-9950-4082-8fa9-73d5bf4b38b6

最佳答案

代替 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

尝试:

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

而不是

"jdbc:sqlserver://192.168.1.35\\SERVER-SQL;" +"database=MainDataBase;"

尝试:

jdbc:microsoft:sqlserver://192.168.1.35\\SERVER-SQL:1433;DatabaseName=MainDataBase

关于java - 与 MS SQL 服务器的连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42946222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com