Setting the Connection Properties
The connection string properties can be specified in various ways:
As name=value properties in the connection URL when you connect by using the DriverManager class.
As name=value properties in the Properties parameter of the Connect method in the DriverManager class.
As values in the appropriate setter method of the data source of the driver. For example:
datasource.setServerName(value) datasource.setDatabaseName(value)
Property names are case-insensitive, and duplicate property names are resolved in the following order:
API arguments (such as user and password)
Property collection
Last instance in the connection string
In addition, unknown values are allowed for the property names, and their values are not validated by the JDBC driver for case sensitivity.
Synonyms are allowed and are resolved in order, just as are duplicate property names.
The following table lists all the currently available connection string properties for the JDBC driver.
Property | Type | Default | Description |
---|---|---|---|
applicationName |
String [<=128 char] |
null |
The application name, or "Microsoft SQL Server 2005 JDBC Driver" if no name is provided. Used to identify the specific application in various SQL Server profiling and logging tools. |
databaseName, database |
String [<=128 char] |
null |
The name of the database to connect to. If not stated, a connection is made to the default database. |
disableStatementPooling |
boolean ["true"|"false"] |
true |
Only the value "true" is currently supported. If set to "false", an exception will occur. |
encrypt |
boolean ["true"|"false"] |
false |
Set to "true" to specify that the SQL Server uses Secure Sockets Layer (SSL) encryption for all the data sent between the client and the server if the server has a certificate installed. The default value is false. |
failoverPartner |
String |
null |
The name of the failover server used in a database mirroring configuration. This property is used for an initial connection failure to the principal server; after you make the initial connection, this property is ignored. Must be used in conjunction with databaseName property.
|
hostNameInCertificate |
String |
null |
The host name to be used in validating the SQL Server SSL certificate. If the hostNameInCertificate property is unspecified or set to null, the Microsoft SQL Server 2005 JDBC Driver will use the serverName property value on the connection URL as the host name to validate the SQL Server SSL certificate. Note This property is used in combination with the encrypt property and the trustServerCertificate property. This property affects the certificate validation, if and only if the encrypt property is set to "true" and the trustServerCertificate is set to "false". |
instanceName |
String [<=128 char] |
null |
The SQL Server 2000 or SQL Server 2005 instance name to connect to. When it is not specified, a connection is made to the default instance. For the case where both the instanceName and port are specified, see the notes for port. |
integratedSecurity |
boolean ["true"|"false"] |
false |
Set to "true" to indicate that Windows credentials will be used by SQL Server to authenticate the user of the application. If "true," the JDBC driver searches the local computer credential cache for credentials that have already been provided at the computer or network logon. If "false," the username and password must be supplied. Note This connection property is only supported on Microsoft Windows operating systems. |
lastUpdateCount |
boolean ["true"|"false"] |
true |
A "true" value only returns the last update count from an SQL statement passed to the server, and it can be used on single SELECT, INSERT, or DELETE statements to ignore additional update counts caused by server triggers. Setting this property to "false" causes all update counts to be returned, including those returned by server triggers. Note This property only applies when it is used with the executeUpdate methods. |
lockTimeout |
int |
-1 |
The number of milliseconds to wait before the database reports a lock time-out. The default behavior is to wait indefinitely. If it is specified, this value is the default for all statements on the connection. Note that |
loginTimeout |
int [0..65535] |
0 |
The number of seconds the driver should wait before timing out a failed connection. A zero value indicates no time-out value. A non-zero value is the number of seconds the driver should wait before timing out a failed connection. |
packetSize |
int [-1| 0 | 512..32767] |
8000 |
The network packet size used to communicate with SQL Server, specified in bytes. A value of -1 indicates using the server default packet size. A value of 0 indicates using the maximum value, which is 32767. If this property is set to a value outside the acceptable range, an exception will occur. Important We do not recommend using the packetSize property when the encryption is enabled (encrypt=true). Otherwise, the driver might raise a connection error. For more information, see the setPacketSize method of the SQLServerDataSource class. |
password |
String [<=128 char] |
null |
The database password. |
portNumber, port |
int [0..65535] |
1433 |
The port where SQL Server is listening. If the port number is specified in the connection string, no request to sqlbrowser is made. When the port and instanceName are both specified, the connection is made to the specified port. However, the instanceName is validated and an error is thrown if it does not match the port. Important We recommend that the port number always be specified, as this is more secure than using sqlbrowser. |
responseBuffering |
String ["full"|"adaptive"] |
full |
If this property is set to "full", the entire result set is read from the server when a statement is executed. The default mode is "full" for the Microsoft SQL Server 2005 JDBC Driver version 1.2 and provides a backward compatibility with the Microsoft SQL Server 2005 JDBC Driver versions 1.0 and 1.1. When this property is set to "adaptive", the minimum possible data is buffered when necessary. The preferred mode is "adaptive" for the Microsoft SQL Server 2005 JDBC Driver version 1.2. |
selectMethod |
String ["direct"|"cursor"] |
direct |
If this property is set to "cursor," a database cursor is created for each query created on the connection for TYPE_FORWARD_ONLY and CONCUR_READ_ONLY cursors. This property is typically required only if the application generates very large result sets that cannot be fully contained in client memory. When this property is set to "cursor," only a limited number of result set rows are retained in client memory. The default behavior is that all result set rows are retained in client memory. This behavior provides the fastest performance when the application is processing all rows. |
sendStringParametersAsUnicode |
boolean ["true"|"false"] |
true |
Set to "false" to specify that prepared parameters for character data are sent as ASCII instead of Unicode. This parameter can improve performance for character data index lookup on non-Unicode, SQL Server 2000, or SQL Server 2005 tables. For example, ASCII row keys can be compared directly without the overhead of conversion from Unicode. For more information, see the Microsoft discussion at support.microsoft.com/kb/271566. |
serverName, server |
String |
null |
The computer running SQL Server. |
userName, user |
String [<=128 char] |
null |
The database user. |
trustServerCertificate |
boolean ["true"|"false"] |
false |
Set to "true" to specify that the Microsoft SQL Server 2005 JDBC Driver will not validate the SQL Server SSL certificate. If "true", the SQL Server SSL certificate is automatically trusted when the communication layer is encrypted using SSL. If "false", the Microsoft SQL Server 2005 JDBC Driver will validate the server SSL certificate. If the server certificate validation fails, the driver will raise an error and terminate the connection. The default value is "false". Note This property is used in combination with the encrypt property. This property only affects the server SSL certificate validation if and only if the encrypt property is set to "true". |
trustStore |
String |
null |
The path (including filename) to the certificate trustStore file. The trustStore file contains the list of certificates that the client trusts. When this property is unspecified or set to null, the driver will rely on the trust manager factory's look up rules to determine which certificate store to use. The default SunX509 TrustManagerFactory tries to locate the trusted material in the following search order:
For more information, see the SUNX509 TrustManager Interface documentation on the Sun Microsystems Web site. Note This property only affects the certificate trustStore lookup, if and only if the encrypt property is set to "true" and the trustServerCertificate property is set to "false". |
trustStorePassword |
String |
null |
The password used to check the integrity of the trustStore data. If the trustStore property is set but the trustStorePassword property is not set, the integrity of the trustStore is not checked. When both trustStore and trustStorePassword properties are unspecified, the driver will use the JVM system properties, "javax.net.ssl.trustStore" and "javax.net.ssl.trustStorePassword". If the "javax.net.ssl.trustStorePassword" system property is not specified, the integrity of the trustStore is not checked. If the trustStore property is not set but the trustStorePassword property is set, the JDBC driver will use the file specified by the "javax.net.ssl.trustStore" as a trust store and the integrity of the trust store is checked by using the specified trustStorePassword. This might be needed when the client application does not want to store the password in the JVM system property. Note The trustStorePassword property only affects the certificate trustStore lookup, if and only if the encrypt property is set to "true" and the trustServerCertificate property is set to "false". |
workstationID |
String [<=128 char] |
<empty string> |
The workstation ID. Used to identify the specific workstation in various SQL Server profiling and logging tools. If none is specified, the <empty string> is used. |
xopenStates |
boolean ["true"|"false"] |
false |
Set to "true" to specify that the driver returns XOPEN-compliant state codes in exceptions. The default is to return SQL 99 state codes. |