com.microsoft.sqlserver.jdbc.SQLServerDriver not found error

前端 未结 8 1960
暖寄归人
暖寄归人 2021-02-13 14:56

I am trying to connect to my SQL Server 2008 database from Java and I\'m having the same problem from this thread.

String userName = \"xxxx\";
String password =          


        
相关标签:
8条回答
  • 2021-02-13 15:28

    For me, it worked once I changed

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    

    to:

    in POM

    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>6.1.0.jre8</version>
    </dependency>
    

    and then:

    import com.microsoft.sqlserver.jdbc.SQLServerDriver;
    

    ...

    DriverManager.registerDriver(SQLServerDriver());    
    Connection connection = DriverManager.getConnection(connectionUrl); 
    
    0 讨论(0)
  • 2021-02-13 15:29

    intellij idea 2019

    1. Download Microsoft JDBC Driver for SQL Server

    (https://docs.microsoft.com/en-us/sql/connect/jdbc/download-microsoft-jdbc-driver-for-sql-server?view=sql-server-2017)

    1. Unpack ("C:\opt\sqljdbc_7.2\enu\mssql-jdbc-7.2.2.jre11.jar")
    2. Add; (File->Project Structure->Global Libraries)
    3. Use; (Adding Jar files to IntellijIdea classpath (look video)) import com.microsoft.sqlserver.jdbc.SQLServerDriver; https://youtu.be/-2hjxoRKsyk

    or ub Gradle set "compile" compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '7.2.2.jre11'

    0 讨论(0)
提交回复
热议问题