public class RDF2Connection {
static Connection connection=null;
final static String connectionUrl = "jdbc:sqlserver://DESKTOP-Q5K9FE6:1433;" +
"databaseName=RDFDB;";
public static Connection getRdf2Connected(){
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
connection = DriverManager.getConnection(connectionUrl, "sa", "root");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return connection;
}
}
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host DESKTOP-Q5K9FE6, port 1433 has failed. Error: "Connection refused: no further information. 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.". at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:206) at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:257) at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2385) at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:567) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1955) at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1616) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1447) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:788) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1187) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at com.rdf2.databaseconnection.RDF2Connection.getRdf2Connected(RDF2Connection.java:22) at MainClass.main(MainClass.java:53) java.lang.NullPointerException at MainClass.main(MainClass.java:54)错误,同时连接的Java与SQL Server 2017年
Process finished with exit code 0
可能与[this]重复(https://stackoverflow.com/questions/18981279/the-tcp-ip-connection-to-the-host-localhost-port-1433-has-failed) –
检查看看如果netbios名称解析为服务器。尝试使用ipadress?或者说Mssqlserver正在运行。 –
看看[this](https://stackoverflow.com/questions/18841744/jdbc-connection-failed-error-tcp-ip-connection-to-host-failed)。你有没有添加DLL? –