Connection Java application with SQL Server

时间:2018-04-28 17:54:39

标签: java sql-server jdbc

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 个答案:

答案 0 :(得分:1)

您在驱动程序类的名称中有错误打印。 将该代码行更改为此Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");