public class OracleDriver
extends oracle.jdbc.driver.OracleDriver
java.sql.Driver
interface.
The JDBC driver registration is automatically done via the Java Standard Edition
Service Provider mechanism introduced in JDK6
. Oracle JDBC driver
implements this feature and it is automatically registered if the Oracle JDBC driver
jar is present in the classpath.
You can open a connection to the database with the static
getConnection()
method of the java.sql.DriverManager
class. The type of the object returned is java.sql.Connection
.
The following signature takes the URL, user name, and password as separate parameters:
getConnection(String URL, String user, String password);
The following signature takes a URL, together with a properties object that specifies user name and password (perhaps among other things):
getConnection(String URL, Properties info);
Where the URL
is of the form:
jdbc:oracle:<drivertype>:@<database>
In addition to the URL, use an object of the standard Java
Properties
class as input. For example:
java.util.Properties info = new java.util.Properties();
info.put ("user", "scott");
info.put ("password","tiger");
info.put ("defaultRowPrefetch","15");
getConnection ("jdbc:oracle:thin:@",info);
Oracle JDBC Thin Driver supports the following URL formats to establish a connection with an Oracle Database. Use any of the below format to establish connection to the Oracle Database.
As the name suggests the EZConnect URL is the easiest option to connect to Oracle.
jdbc:oracle:thin:@[[protocol:]//]
host1[,host12,host13][:port1][,host2:port2]/service_name[:server][/instance_name]
[?[parameter-name1=parameter-value1][¶meter-name2=parameter-value2],...]
In the above format, the parts that are enclosed in square brackets are optional. TCP and TCPS are supported
protocols. Specifying the protocol is optional and the default value is TCP. The URL must contain
at least one database host name. Multiple host names are separated by a comma. The host name is followed by an
optional port number. If multiple hosts share the same port number then the port number can be specified at the end of
the host names list. The default port value is 1521
.
Host and port information is followed by the database service name which is in turn followed by
the optional server mode and the database instance name.
The supported server modes are dedicated|shared|pooled
.
An EZConnect URL can have an optional list of name-value pairs as parameters after the '?' delimiter.
Name and value are separated by an '=' and multiple properties are separated by an '&'.
The Thin driver creates a TNS URL using the information provided in the EZConnect format. While resolving
to the TNS format, a name-value pair specified in the EZConnect format is resolved to a TNS URL parameter. If a
name-value pair can not be resolved to a TNS URL parameter then it is handled as a connection property.
The list of supported name value pairs are as follows
Parameter Name | Description |
---|---|
ssl_server_dn_match | Specifies if DN matching is to be enforced. Applicable only for TCPS connection and the default is ON. |
ssl_server_cert_dn | Specifies the DN of the database server. |
https_proxy | Specifies proxy host to be used while establishing connection to the Oracle Database. |
https_proxy_port | Specifies proxy port to be used while establishing connection to the Oracle Database. |
enable | The keepalive feature on the supported TCP transports can be enabled for a client by
specifying enable=broken |
failover | To enable or disable connect-time failover for multiple protocol addresses.
Supported values on | off |
load_balance | To enable or disable client load balancing for multiple protocol addresses.
Supported values on | off |
recv_buf_size | To specify, in bytes, the buffer space for receive operations of sessions |
send_buf_size | To specify, in bytes, the buffer space for send operations of sessions. |
sdu | To instruct JavaNet to optimize the transfer rate of data packets being sent across the network with a specified session data unit (SDU) size in bytes. |
source_route | To enable routing through multiple protocol addresses.
Supported values on | off |
retry_count | To specify the number of times an ADDRESS list is traversed before the connection attempt is terminated. The default value is 0. |
retry_delay | To specify the delay in seconds between subsequent retries for a connection.
This parameter works in conjunction with retry_count parameter. |
service_tag | To specify the value of service tag. While establishing connection to the Oracle Database, the configured value is sent as part of connect data. |
pool_connection_class | Use this parameter to explicitly name the connection class for DRCP connection. |
pool_purity | Use this parameter to specify if an application needs a new session that is not
tainted with any prior session state or to reuse a previous session.
Supported values are NEW | SELF . |
Parameter Name | Description |
---|---|
wallet_location | Specifies the location of the wallet file. More Info.. |
ssl_ciphers | Use this to specify the set of cipher suites to be used while SSL protocol negotiation. More Info.. |
connect_timeout | To specify the timeout duration in seconds for a client to establish an Oracle Net session to an Oracle database. More Info.. |
transport_connect_timeout | To specify the transportation timeout duration in seconds for a client to establish an network connection to an Oracle Database. More Info.. |
encryption_client | Specifies the encryption level supported by client. Supported values are accepted | rejected | requested | required
More Info..
|
encryption_types_client | Specifies the list of encryption algorithms supported by client. Supported algorithms are AES128, AES192, AES256, RC4_40, RC4_56, RC4_128, RC4_256,
DES, DES40, 3DES112, 3DES168.
More Info..
|
crypto_checksum_client | Specifies the data integrity level supported by client.
Supported values are accepted | rejected | requested | required
More Info..
|
crypto_checksum_types_client | Specifies the list of data integrity algorithms supported by client.
Supported algorithms are SHA256, SHA384, SHA512, SHA1, MD5
More Info..
|
Other connection properties specified in oracle.jdbc.OracleConnection
can also be configured
through EZConnect format. Please use the value of the connection property constant name declared in
oracle.jdbc.OracleConnection for configuring the property.
Connection property constant names start with CONNECTION_PROPERTY_
.
This is a descriptive format. Each section is enclosed in parenthesis. Please refer to the Oracle Net Services documentation to know more about the TNS formats and the details of all the supported parameters.
jdbc:oracle:thin:@(DESCRIPTION= (ADDRESS=(protocol_address_information)) (CONNECT_DATA= (SERVICE_NAME=service_name)))
jdbc:oracle:thin:@(DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=sales-svr)(PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=sales.us.example.com)))
jdbc:oracle:thin:@(DESCRIPTION= (ADDRESS_LIST= (ADDRESS=(PROTOCOL=tcp)(HOST=sales1-svr)(PORT=1521)) (ADDRESS=(PROTOCOL=tcp)(HOST=sales2-svr)(PORT=1521))) (CONNECT_DATA=(SERVICE_NAME=sales.us.example.com)))
jdbc:oracle:thin:@(DESCRIPTION= (LOAD_BALANCE=on) (FAILOVER=on) (ADDRESS_LIST= (SOURCE_ROUTE=yes) (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=1630)) (ADDRESS=(PROTOCOL=tcp)(HOST=host2)(PORT=1521))) (ADDRESS_LIST= (SOURCE_ROUTE=yes) (ADDRESS=(PROTOCOL=tcp)(HOST=host3)(port=1630)) (ADDRESS=(PROTOCOL=tcp)(HOST=host4)(port=1521))) (CONNECT_DATA=(SERVICE_NAME=sales.us.example.com)))
An alias declared in a tnsnames.ora file present in the TNS ADMIN directory can also be used
in the URL. At runtime the JDBC Thin Driver resolves the specified alias by referring to the
tnsnames.ora file. The TNS ADMIN directory can be specified through the URL or through the
connection property oracle.net.tns_admin
. Any environmental variables in the
specified TNS ADMIN path will be resolved automatically.
jdbc:oracle:thin:@<alias-name>
jdbc:oracle:thin:@<alias-name>?TNS_ADMIN=/work/tnsadmin/
jdbc:oracle:thin:@inst1
jdbc:oracle:thin:@inst1?TNS_ADMIN=/work/tnsadmin/
jdbc:oracle:thin:@inst1?TNS_ADMIN=$ORACLE_HOME/tnsadmin/
jdbc:oracle:thin:@inst1?TNS_ADMIN=%ORACLE_HOME%/tnsadmin/
The JDBC Thin driver can retrive the TNS URL from an LDAP server. Use the following format for
configuring the LDAP server details. JDBC Thin Driver uses the value of the orclnetdescstring
attribute under the specified DN. If the LDAP connection is established using TCPS (ldaps) connection then
the wallet / keystore
properties can be specified through connection properties. Please see
the LDAP connection properties in the below table. Optionally you can configure LDAP authentication
details through connection properties or through wallet secret store.
Property Name | Description |
---|---|
oracle.net.ldap.ssl.walletLocation | Use this property to specify the wallet location. The driver will use this wallet while SSL negotiation with LDAP server. More Info.. |
oracle.net.ldap.ssl.walletPassword | Use this property to specify the password of the wallet file which will be used while SSL negotiation with LDAP Server. More Info.. |
oracle.net.ldap.security.authentication | Specifies the authentication mechanism to be used by the LDAP service provider
in the JDK. Supported values none | simple .
More Info..
|
oracle.net.ldap.security.principal | Use this property to specify the value of the username(DN) which will be used
while authenticating with the LDAP server. This property can also be configured
via wallet secret store entry oracle.ldap.client.dn
More Info..
|
oracle.net.ldap.security.credentials | Use this property to configure the password which will be used while authenticating
with the LDAP server. This property can also be configured
via wallet secret store entry oracle.ldap.client.password
More Info..
|
jdbc:oracle:thin:@ldap://<ldap-host>:<ldap-port>/<dn>
jdbc:oracle:thin:@ldaps://<ldap-host>:<ldap-port>/<dn>
jdbc:oracle:thin:@ldap://myldapserver:2636/cn=orcl,cn=OracleContext,dc=example,dc=com
jdbc:oracle:thin:@ldaps://myldapserver:1636/cn=orcl,cn=OracleContext,dc=example,dc=com
oracle.jdbc.OracleConnection
contains
constant fields for almost all the properties supported by the JDBC Driver.
The name of the constants start with CONNECTION_PROPERTY_
. In Java code, the
constants fields can be used directly. Use the String value of a constant field to configure
the property through a URL or through a properties file. The following are the different methods of
configuring JDBC connection properties.
While using the EZConnect URL format, the connection properties can be configured via URL. After the '?' delimiter, Easy Connect supports a list of parameters as name-value pairs which can be optionally specified. The name and value of a connection property is separated by an '=' and multiple properties are separated by an '&'
jdbc:oracle:thin:@//salesserver1:1521/sales.us.example.com?oracle.net.networkCompression=on
jdbc:oracle:thin:@//salesserver1:1521/sales.us.example.com?oracle.net.networkCompression=on&oracle.net.networkCompressionThreshold=1024
Connection properties can also be configured via a properties file named ojdbc.properties
.
This properties file should be present under the TNS ADMIN directory. The TNS ADMIN directory can be
configured through the URL.
jdbc:oracle:thin:@//salesserver1:1521/sales.us.example.com?TNS_ADMIN=$ORACLE_HOME/tnsadmin/
jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=sales-svr)(PORT=1521))
(CONNECT_DATA=(SERVICE_NAME=sales.us.example.com))?TNS_ADMIN=$ORACLE_HOME/tnsadmin/
Connection properties can be configured through System properties as well. The below example shows how to configure a system property for a standalone Java application.
java -Doracle.net.networkCompression=on MyApp
The JDBC Driver supports multiple authentication mechanisms:
A username and password pair is used to authenticate to the Oracle Database Server. The username and password are specified using the following options.
jdbc:oracle:thin:myuser/mypassword@//salesserver1:1521/sales.us.example.com
oracle.net.wallet_location
the JDBC Thin driver retrives the username and password
from the wallet. Please refer to Oracle documentation on how to store the username and password to
the wallet file.The JDBC Driver can authenticate to the Oracle Database using a certificate from a wallet / keystore.
For this, the Oracle Database Server has to be configured to support the TCPS authentication.
And, the JDBC driver must be configured with the connection property
oracle.net.authentication_services = (TCPS)
along with wallet / keystore
properties.
The JDBC Driver can authenticate to the Oracle Database using Kerberos.
For this, the Oracle Database Server has to be configured to support Kerberos authentication.
Please refer to Oracle documentation on how to configure the Oracle Database for Kerberos authentication.
Configure the following connection properties to enable Kerberos authentication in the JDBC Driver.
oracle.net.authentication_services=(KERBEROS5)
Additional configuration can be specified in a configuration file indicated by
the system property
oracle.net.kerberos5_mutual_authentication=true
oracle.net.kerberos5_cc_name=<path to the kerberos credentials cache file>
java.security.krb5.conf
. Please refer to JDK
documentation for more information.
The JDBC Driver can authenticate to the Oracle Database using RADIUS. For this, the Oracle Database Server has to be configured to support RADIUS authentication. Please refer to Oracle documentation on how to configure the Oracle Database for RADIUS authentication. Configure the following connection properties to enable RADIUS authentication in the JDBC driver.
oracle.net.authentication_services=(RADIUS) user=<username> password=<passcode>
Oracle provides four types of JDBC driver.
thin
. To connect user scott
with password
tiger
to a database with SID
(system identifier)
orcl
through port 1521 of host myhost
, using the Thin
driver, you would write :
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@myhost:1521:orcl", "scott", "tiger");
oci
. To connect user scott
with password tiger
to a database with SID
(system
identifier) orcl
through port 1521 of host myhost
,
using the OCI driver, you would write :
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci:@myhost:1521:orcl", "scott", "tiger");
Note that you can also specify the database by a TNSNAMES
entry.
You can find the available TNSNAMES
entries listed in the file
tnsnames.ora
on the client computer from which you are connecting.
For example, if you want to connect to the database on host myhost
as user scott
with password tiger
that has a
TNSNAMES
entry of MyHostString
, enter:
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:@MyHostString","scott","tiger");
If your JDBC client and Oracle server are running on the same machine, the
OCI driver can use IPC (InterProcess Communication) to connect to the database
instead of a network connection. An IPC connection is much faster than a
network connection.
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:@","scott","tiger");
thin
and there is no difference
in your code between using the Thin driver from a client application or from
inside a server.kprb
and it actually runs within a default
session. You are already "connected". Therefore the connection should never
be closed.You can also use the Oracle-specific defaultConnection() method of the OracleDriver class which is generally recommended:DriverManager.getConnection("jdbc:oracle:kprb:");
or:DriverManager.getConnection("jdbc:default:connection:");
OracleDriver ora = new OracleDriver();
Connection conn = ora.defaultConnection();
Note: You are no longer required to register the OracleDriver
class for connecting with the Server-Side Internal driver, although there is
no harm in doing so. This is true whether you are using
getConnection()
or defaultConnection()
to make the
connection.DriverManager.getConnection()
method returns a new Java Connection
object every time you call it.
Note that although the method is not creating a new physical connection (only a
single implicit connection is used), it is returning a new object.access_string, accumulate_batch_result, batch_string, convert_nchar_literals_string, database_string, dataSizeBytes, dataSizeChars, dataSizeUnitsPropertyName, DEFAULT_CONNECTION_PROPERTIES, default_execute_batch_string, default_row_prefetch_string, defaultConn, defaultnchar_string, defaultncharprop_string, disable_defineColumnType_string, dll_string, execute_batch_string, fixed_string_string, include_synonyms_string, j2ee_compliance, jdbc_string, logon_as_internal_str, nls_lang_backdoor, no_caching_buffers, oracle_string, password_string, permit_timestamp_date_mismatch_string, prefetch_string, prelim_auth_string, process_escapes_string, protocol_string, protocolFullName_string, proxy_client_name, read_timeout, remarks_string, report_remarks_string, restrict_getTables_string, retain_v9_bind_behavior_string, row_prefetch_string, server_string, set_new_password_string, SetFloatAndDoubleUseBinary_string, synonyms_string, systemTypeMap, tcp_no_delay, useFetchSizeWithLongColumn_prop_string, useFetchSizeWithLongColumn_string, user_string, v8compatible_string, xa_trans_loose
Constructor and Description |
---|
OracleDriver() |
Modifier and Type | Method and Description |
---|---|
static String |
getBuildDate()
Returns a String that specifies exactly when the jar file was
built.
|
static String |
getDriverVersion()
Returns a String that specifies the Oracle version number
of the driver.
|
static String |
getJDBCVersion()
Returns a String that specifies the version of the JDBC
spec supporte by the driver.
|
static boolean |
isDebug()
Returns true if this jar includes debug code.
|
static boolean |
isDMS()
Returns true if this jar includes DMS instrumentaion.
|
static boolean |
isInServer()
Returns true if this jar was built to run in the Oracle Java VM.
|
static boolean |
isJDK14()
Deprecated.
|
static boolean |
isPrivateDebug()
Returns true if this jar includes Oracle internal debug code.
|
static void |
main(String[] args)
Prints a description of the Oracle JDBC driver .jar file
to System.out.
|
_INTERNAL_ORACLE_connectAsync, acceptsURL, connect, connect, defaultConnection, getCompileTime, getExecutorService, getMajorVersion, getMinorVersion, getMonitorLock, getParentLogger, getPropertyInfo, getSystemPropertyDateZeroTime, getSystemPropertyDateZeroTimeExtra, getSystemPropertyFastConnectionFailover, jdbcCompliant, processSqlEscapes, registerMBeans, setExecutorService, unRegisterMBeans
public static final boolean isDMS()
public static final boolean isInServer()
public static final boolean isJDK14()
public static final boolean isDebug()
public static final boolean isPrivateDebug()
public static final String getJDBCVersion()
public static final String getDriverVersion()
public static final String getBuildDate()