Overview of Connecting to Oracle Database

In Java, you use an instance of the DataSource object to get a connection to the database. The DataSource interface provides a complete replacement for the previous JDBC DriverManager class. Oracle implements the javax.sql.DataSource interface with the OracleDataSource class in the oracle.jdbc.pool package. The overloaded getConnection method returns a physical connection to the database.

Note:

The use of the DriverManager class to establish a connection to a database is deprecated.

You can either set properties using appropriate setxxx methods for the DataSource object or use the getConnection method that accepts these properties as input parameters.

Important DataSource Properties are listed in Table 3-1.

Table 3-1 Standard Data Source Properties

Name Type Description

databaseName

String

Name of the particular database on the server. Also known as the service name (or SID) in Oracle terminology.

dataSourceName

String

Name of the underlying data source class.

description

String

Description of the data source.

networkProtocol

String

Network protocol for communicating with the server. For Oracle, this applies only to the JDBC Oracle Call Interface (OCI) drivers and defaults to tcp.

password

String

Password for the connecting user.

portNumber

int

Number of the port where the server listens for requests

serverName

String

Name of the database server

user

String

User name to be used for login

driverType

String

Specifies the Oracle JDBC driver type. It can be either oci or thin.

This is an Oracle-specific property.

url

String

Specifies the URL of the database connect string.You can use this property in place of the standard portNumber, networkProtocol, serverName, and databaseName properties.

This is an Oracle-specific property.

If you choose to set the url property of the DataSource object with all necessary parameters, then you can connect to the database without setting any other properties or specifying any additional parameters with the getDBConnection method. For more information about setting the database URL, refer to the Specifying Database URLs section.

Note:

The parameters specified through the getConnection method override all property and url parameter settings previously specified in the application.