JDBC URL to connect to SQL Server with instance

JDBC URL to connect to SQL Server with instance

book

Article ID: KB0075131

calendar_today

Updated On:

Products Versions
Spotfire Server All Versions

Description

SQL Server allows the installation of multiple database instances per server. Below are the JDBC url examples to connect to SQL Server with named instance

Issue/Introduction

JDBC url to connect to SQL Server with instance

Environment

All Supported OS

Resolution

Option 1
Below is the default url to connect to the SQL Server database with the instance name
 
  • jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]

where:
  • jdbc:sqlserver:// (Required) is known as the subprotocol and is constant.

  • serverName (Optional) is the address of the server to connect to. This could be a DNS or IP address, or it could be localhost or 127.0.0.1 for the local computer. If not specified in the connection URL, the server name must be specified in the properties collection.

  • instanceName (Optional) is the instance to connect to on serverName. If not specified, a connection to the default instance is made.

  • portNumber (Optional) is the port to connect to on serverName. The default is 1433. If you're using the default, you don't have to specify the port, nor its preceding ':', in the URL.
  • propertyvalue(Optional) : More information about the property value list can be found at https://docs.microsoft.com/en-us/sql/connect/jdbc/setting-the-connection-properties?view=sql-server-2017

e.g. jdbc:sqlserver://test-server\sqlexpress:1433;databaseName=master;

Option 2

Below is the url where we specify the instance name as a JDBC URL property, if no instance name or port number property is specified, a connection to the default instance is created

  • jdbc:sqlserver://<hostname>;instanceName=<instance_name>;databaseName=<database_name>;

Additional Information

https://docs.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url?view=sql-server-2017