Installing Microsoft JDBC Driver for SQL Server

This section describes how to download and install Microsoft JDBC Driver for SQL Server.

If you want to access SQL Server database from Java applications, you need to install a JDBC driver that supports SQL Server. There are many software vendors offer such JDBC drivers.

Microsoft offers a free driver called "Microsoft JDBC Driver for SQL Server". Here is how download and install it.

1. Go to Microsoft JDBC Driver for SQL Server Website at https://docs.microsoft.com/en-us/sql/connect/jdbc/microsoft-jdbc-driver-for-sql-server.

2. Click the Download link. You see a list of different versions.

3. Select a version that is compatible with SQL Server version and JVM version according the table below. Take the latest version, if you are not sure.

JDBC Driver         JVM      SQL Server
-----------   ---------   -------------
        9.4   8, 11, 16     2012 - 2019
        8.4   8, 11, 14     2012 - 2019
        7.4   8, 11, 12     2012 - 2016
        7.2       8, 11   2008R2 - 2016
        7.0       8, 10   2008R2 - 2016
        6.4     7, 8, 9   2008R2 - 2016
        6.2        7, 8     2008 - 2016
        6.1        7, 8     2008 - 2016
        6.0        7, 8     2008 - 2016
        4.2        7, 8     2008 - 2016
        4.1           7     2008 - 2016
        4.0     5, 6, 7     2008 - 2016

2. Select "English" as the language and click "Download". And save the downloaded file as sqljdbc_9.4.1.0_enu.zip.

3. Unpackage the downloaded file. You should get a sub-directory with these files:

herong> dir sqljdbc_9.4\enu\

          auth
    1,182 install.txt
   12,112 license.txt
1,358,690 mssql-jdbc-9.4.1.jre11.jar
1,358,629 mssql-jdbc-9.4.1.jre16.jar
1,346,759 mssql-jdbc-9.4.1.jre8.jar
      199 redist.txt
    7,882 release.txt
          samples
   12,563 thirdpartynotices.txt
          xa

4. Copy the correct version of the JAR file, like mssql-jdbc-9.4.1.jre16.jar, to the working directory.

Note that JDBC Driver JAR file names of newer versions become more clear than older versions. JAR file names of older versions are listed below together with their compatible JDBC versions.

JDBC Driver   JAR File        JDBC API   JDK
Version       Name            Version    Version
-----------   --------        --------   -------
1.0           sqljdbc.jar     2.0        1.5

2.0           sqljdbc.jar     3.0        1.5
2.0           sqljdbc4.jar    4.0        1.6

3.0           sqljdbc.jar     3.0        1.5
3.0           sqljdbc4.jar    4.0        1.6

4.0           sqljdbc.jar     3.0        1.5
4.0           sqljdbc4.jar    4.0        1.6

4.1           sqljdbc.jar     3.0        1.5
4.1           sqljdbc4.jar    4.0        1.6
4.1           sqljdbc41.jar   4.1        1.7

4.2           sqljdbc.jar     3.0        1.5
4.2           sqljdbc4.jar    4.0        1.6
4.2           sqljdbc41.jar   4.1        1.7
4.2           sqljdbc42.jar   4.2        1.8

Table of Contents

 About This Book

 JDBC (Java Database Connectivity) Introduction

 JDK (Java SE) Installation

 Microsoft SQL Server Express Edition

Microsoft JDBC Driver for SQL Server

Installing Microsoft JDBC Driver for SQL Server

 Loading Driver Class Automatically

 Loading Driver Class with Class.forName()

 DriverManager.getConnection() and Connection URL

 Enable TCP/IP with SQL Server Configuration Manager

 Specifying Port Number in Connection URL

 Instance Name Better than Port Number

 Specifying Instance Name in Connection URL

 Closing the Database Connection - con.close()

 Specifying Database Name in Connection URL

 Incorrect Database Name in Connection URL

 Creating Connections with DataSource Class

 Microsoft JDBC Driver - Query Statements and Result Sets

 Microsoft JDBC Driver - DatabaseMetaData Object

 Microsoft JDBC Driver - DDL Statements

 Microsoft JDBC Driver - DML Statements

 SQL Server - PreparedStatement

 SQL Server CLOB (Character Large Object) - TEXT

 SQL Server BLOB (Binary Large Object) - BLOB

 Using Connection Pool with JDBC

 JDBC-ODBC Bridge Driver - sun.jdbc.odbc.JdbcOdbcDriver

 JDBC-ODBC Bridge Driver - Flat Text Files

 JDBC-ODBC Bridge Driver - MS Access

 JDBC-ODBC Bridge Driver - MS SQL Server

 Archived Tutorials

 References

 Full Version in PDF/EPUB