0
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)

Process finished with exit code 0

Tome
  • 3,234
  • 3
  • 33
  • 36
  • Possible duplicate with [this](https://stackoverflow.com/questions/18981279/the-tcp-ip-connection-to-the-host-localhost-port-1433-has-failed) – TuyenNTA Jun 05 '17 at 22:39
  • Check to see if the netbios name resolve to the server. Try use ipadress instead? Or that the Mssqlserver is running. – Minh Kieu Jun 05 '17 at 22:42
  • Take a look at [this](https://stackoverflow.com/questions/18841744/jdbc-connection-failed-error-tcp-ip-connection-to-host-failed). Have you added the dll? – Marco Luzzara Jun 05 '17 at 22:49
  • `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`: Pretty clear. – chrylis -cautiouslyoptimistic- Jun 05 '17 at 23:18

2 Answers2

0

Can you see if the SQL Server is only listening on an IPv6 port? If so you can use the following

System.setProperty("java.net.preferIPv6Addresses", "true"); 

That would be my only suggestion as far as code changes. Possibly try and use the IP as opposed to the name. If that doesn't work you need to go to your SQL Server and verify that it accepts TCP/IP connections, or check your local firewall settings. At that point the question would be more appropriate for server exchange.

Chris Maggiulli
  • 3,375
  • 26
  • 39
0

just make sure this the the correct port

this is the true answer Thanks.