1

So I'm trying to do UDT using in Java with my eclipse and SQL server 2014:

This is the part of the code where I connect my SQL server to my eclipse, I already installed the JDBC jar to the path.

Connection con = null;   PreparedStatement statement = null; //to take care of the sql statements to be run  
         //Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

         con = DriverManager.getConnection("jdbc:sqlserver://localhost‌​;databaseName=Company;integratedSecurity=true;");
         //con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433‌​;databaseName=MASTER‌​;user=sa;password=Se‌​cret");

This is my error output, although I haven't created my tables in SQL server yet, I want try to see if eclipse is connected to SQL server 2014, so far this is error I have:

Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host localhost‌​, port 1433 has failed. Error: "localhost‌​. 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:191)
    at com.microsoft.sqlserver.jdbc.SQLServerException.ConvertConnectExceptionToSQLServerException(SQLServerException.java:242)
    at com.microsoft.sqlserver.jdbc.SocketFinder.findSocket(IOBuffer.java:2369)
    at com.microsoft.sqlserver.jdbc.TDSChannel.open(IOBuffer.java:551)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1963)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1628)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1459)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:773)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1168)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at insertion.insert_values(insertion.java:12)
    at PointType.main(PointType.java:65)

Don't worry about my insertion part, I just want to know why my port connection is failing?

I tried everything but so far still connection is not working, what could be causing it?

JavaAmateur
  • 47
  • 1
  • 8

1 Answers1

1

You've misspelled "localhost" in your URL

Joey_89
  • 31
  • 7
  • oh sir I've changed that, still got the wrong answer – JavaAmateur Mar 23 '17 at 23:39
  • How about... con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=MASTER;user=sa;password=Secret"); – Joey_89 Mar 23 '17 at 23:51
  • also curious sir since I've created the table in SQL that will work with my java yet, so if this error is fixed, other error will occur on output instead of connection error right? – JavaAmateur Mar 23 '17 at 23:53
  • Sorry, I don't understand. Can you rephrase that? – Joey_89 Mar 24 '17 at 00:00
  • I updated my question, please take a look – JavaAmateur Mar 24 '17 at 00:01
  • Had a look. I'm not familiar with SQL Server. I imagine Microsoft provide a way for you to tell which port the server is running on. Is your Java application also running on the same machine? – Joey_89 Mar 24 '17 at 00:14
  • 1433 is my port number, how do I make sure the Java pplication is running on the same machine? – JavaAmateur Mar 24 '17 at 00:23
  • I'm assuming that the computer on which SQL server is running is the same computer on which you are running your Java application. But if you're running your Java application on a different computer, then you have a network issue. Localhost means local to a single computer. Since your SQL server is running on localhost, applications running on different computers will never be able to connect to it. – Joey_89 Mar 24 '17 at 00:35