1

I am trying to connect my java application with Microsoft SQL Server DBMS. here is my connection string:

try{
    String host = "jdbc:sqlserver://localhost:1433;databaseName=JITM;integratedSecurity=true";
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerh=Driver");
    con = DriverManager.getConnection(host);
    stmt = con.createStatement();
    System.out.println("Connection Successful");
}catch(SQLException err){
    System.out.println(err.getMessage());
}catch (ClassNotFoundException ex) {
        System.out.println(ex.getMessage());
}

it display this error.

com.microsoft.sqlserver.jdbc.SQLServerh=Driver

i have added sqljdbc41.jar in the libraries. the database is windows authentication.

1 Answers1

1

You have a misprint in the name of a driver class. Change that code line to this Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

Ivan
  • 8,508
  • 2
  • 19
  • 30
  • i changed, now it gives this error: The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. 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.". – Aliyu Heidar Umar Apr 28 '18 at 18:01
  • 2
    @AliyuHeidarUmar, are you sure that database is up and running and that port in URL is correct? And that port 1433 is not blocked by firewall? – Ivan Apr 28 '18 at 18:04
  • Yes, The database is on the local machine, and i don`t have any firewall on it. – Aliyu Heidar Umar Apr 28 '18 at 18:20
  • 1
    @AliyuHeidarUmar try answers from these links: https://stackoverflow.com/questions/18841744/jdbc-connection-failed-error-tcp-ip-connection-to-host-failed, https://kb.sos-berlin.com/pages/viewpage.action?pageId=17499564 – Ivan Apr 28 '18 at 18:23