14

I want to connect my Java SpringBoot app to SQL Server and I get the information that spring cannot load driver class. I tried:

spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver

and

spring.datasource.driver-class-name=com.microsoft.jdbc.sqlserver.SQLServerDriver

But both did not work, here is my maven dependency

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>7.0.0.jre8</version>
    <scope>test</scope>
</dependency>
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
Clyde Barrow
  • 1,924
  • 8
  • 30
  • 60

2 Answers2

25

According to this web page, the correct property is spring.datasource.driverClassName.

So, the full connection string should be:

spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
Shepard62FR
  • 290
  • 3
  • 11
0

A complete snippet

<resources>
    <jdbc-connection-pool 
        name="microsoft_sqlserver2005_pool" 
        datasource-classname="com.microsoft.sqlserver.jdbc.SQLServerDataSource"
        res-type="javax.sql.DataSource">
        <property name="user" value="DB_USER"/>
        <property name="password" value="DB_PASSWORD"/>
        <property name="serverName" value="DB_HOSTNAME"/>
        <property name="portNumber" value="1433"/>
        <property name="databaseName" value="DATABASE_NAME"/>
    </jdbc-connection-pool>

    <jdbc-resource 
        enabled="true" 
        jndi-name="jdbc/microsoft_sqlserver2005_resource" 
        object-type="user" 
        pool-name="microsoft_sqlserver2005_pool"/>
</resources>
Jess N
  • 11
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 17 '23 at 12:46