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 Answer 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");
answered Apr 28, 2018 at 17:56
Ivan
8,7682 gold badges23 silver badges31 bronze badges
Sign up to request clarification or add additional context in comments.
4 Comments
Aliyu Heidar Umar
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.".
Ivan
@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?
Aliyu Heidar Umar
Yes, The database is on the local machine, and i don`t have any firewall on it.
Ivan
@AliyuHeidarUmar try answers from these links: stackoverflow.com/questions/18841744/…, kb.sos-berlin.com/pages/viewpage.action?pageId=17499564
default