The fact it works when you use Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
and a JDBC URL that starts with jdbc:microsoft:sqlserver
indicates you are using the +/- 17 year old Microsoft SQL Server 2000 JDBC driver. This driver predates JDBC 4, so it does not support the driver auto-loading through /META-INF/services/java.sql.Driver
.
Since the SQL Server 2005 JDBC driver, the correct class name is com.microsoft.jdbc.sqlserver.SQLServerDriver
(note that jdbc
and sqlserver
switched places) and the URL prefix changed to jdbc:sqlserver:
(see also this blogpost). I believe that JDBC 4 autoloading was added in the SQL Server 2008 JDBC driver. See Microsoft JDBC Driver for SQL Server for more information.
If you want to take advantage of the driver auto-loading, you will need to upgrade your driver to a newer version (the latest preferably) and change your configuration.
See: https://github.com/Microsoft/mssql-jdbc and the Microsoft Download Center