我想通过java,Intellij连接到SQL Server,我在.gradle文件中添加存储库,如下所示:
// https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc
testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.2.2.jre7'
// https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc
testCompile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.2.2.jre8'
之后,我尝试通过以下代码连接:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://IpAddress:1433;databaseName=DbName";
String username = "user";
String password = "pass";
Connection conn = DriverManager.getConnection(url,username,password);
我收到了这个错误:
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
我很惊讶因为这个代码在Eclipse中使用相同的jar文件,但在intellij中没有!