Setting up maven dependency for SQL Server Setting up maven dependency for SQL Server sql-server sql-server

Setting up maven dependency for SQL Server


Download the driver JAR from the link provided by Olaf and add it to your local Maven repository with;

mvn install:install-file -Dfile=sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=4.0 -Dpackaging=jar

Then add it to your project with;

<dependency>  <groupId>com.microsoft.sqlserver</groupId>  <artifactId>sqljdbc4</artifactId>  <version>4.0</version></dependency>


Answer for the "new" and "cool" Microsoft.

Yay, SQL Server driver now under MIT license on

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

Answer for the "old" Microsoft:

For my use-case (integration testing) it was sufficient to use a system scope for the JDBC driver's dependency as such:

<dependency>    <groupId>com.microsoft.sqlserver</groupId>    <artifactId>sqljdbc4</artifactId>    <version>3.0</version>    <scope>system</scope>    <systemPath>${basedir}/lib/sqljdbc4.jar</systemPath>    <optional>true</optional></dependency>

That way, I could put the JDBC driver into local version control. No need to have each developer manually set stuff up in their own repositories.

I took inspiration from this answer to another Stack Overflow question and I've also blogged about it here.


There is also an alternative: you could use the open-source jTDS driver for MS-SQL Server, which is compatible although not made by Microsoft.For that driver, there is a maven artifact that you can use:

http://jtds.sourceforge.net/

From http://mvnrepository.com/artifact/net.sourceforge.jtds/jtds :

<dependency>    <groupId>net.sourceforge.jtds</groupId>    <artifactId>jtds</artifactId>    <version>1.3.1</version></dependency>

UPDATE nov 2016, Microsoft now published its MSSQL JDBC driver on github and it's also available on maven now:

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