Setting up maven dependency for SQL Server

后端 未结 8 1746
小鲜肉
小鲜肉 2020-11-28 02:07

I am developing a portlet where I have Hibernate access to SQL Server database. I set up maven dependencies for it and try to find out SQL Server connector

相关标签:
8条回答
  • 2020-11-28 02:45

    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>
    
    0 讨论(0)
  • 2020-11-28 02:48

    Even after installing the sqlserver jar, my maven was trying to fetch the dependecy from maven repository. I then, provided my pom the repository of my local machine and it works fine after that...might be of help for someone.

        <repository>
            <id>local</id>
            <name>local</name>
            <url>file://C:/Users/mywindows/.m2/repository</url>
        </repository>
    
    0 讨论(0)
  • 2020-11-28 02:50
    <dependency>
      <groupId>com.hynnet</groupId>
      <artifactId>sqljdbc4-chs</artifactId>
      <version>4.0.2206.100</version>
    </dependency>
    

    This worked for me(if you use maven)

    https://search.maven.org/artifact/com.hynnet/sqljdbc4-chs/4.0.2206.100/jar

    0 讨论(0)
  • 2020-11-28 02:53

    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>
    
    0 讨论(0)
  • 2020-11-28 03:01

    Be careful with the answers above. sqljdbc4.jar is not distributed with under a public license which is why it is difficult to include it in a jar for runtime and distribution. See my answer below for more details and a much better solution. Your life will become much easier as mine did once I found this answer.

    https://stackoverflow.com/a/30111956/3368958

    0 讨论(0)
  • 2020-11-28 03:01

    It looks like Microsoft has published some their drivers to maven central:

    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>6.1.0.jre8</version>
    </dependency>
    
    0 讨论(0)
提交回复
热议问题