I am trying to create a connection between some Java and a SQL Server using a JDBC driver. I have created a Connection class which should form the connection to a server which is on my computer with example IP address 'BHX'
Here is the Connection class
public class Connection {
public static void main(String[] args) throws Exception {
try {
String databaseDriver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(databaseDriver);
} catch (Exception e) {
e.printStackTrace();
}
try {
String url = "jdbc:jtds:sqlserver://BHX:1433/Forecast;instance=SQLEXPRESS";
java.sql.Connection con = DriverManager.getConnection(url);
System.out.println("Connection created");
con.close();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
I'm wondering whether there is anything wrong with the url String, as when I run this code I get the following error:
java.sql.SQLException: Network error IOException: Connection refused: connect
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:417)
at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:185)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Connection.main(Connection.java:56)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.sourceforge.jtds.jdbc.SharedSocket.createSocketForJDBC3(SharedSocket.java:311)
at net.sourceforge.jtds.jdbc.SharedSocket.<init>(SharedSocket.java:261)
at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:318)
... 5 more
I have seen similar questions (like this here) but its looks as though I have followed all the possible solutions. I have checked that the TCP/IP are enabled in the configuration manager and also that the port number is 1433.
I've tried running this with Firewalls disabled and still get the same error.
telnet BHX 1433 and I am getting the following message '...Could not open connection to the host, on port 1433: Connect failed'