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 |
|---|---|---|
|
|
|
Name of the particular database on the server. Also known as the service name (or SID) in Oracle terminology. |
|
|
|
Name of the underlying data source class. |
|
|
|
Description of the data source. |
|
|
|
Network protocol for communicating with the server. For Oracle, this applies only to the JDBC Oracle Call Interface (OCI) drivers and defaults to |
|
|
|
Password for the connecting user. |
|
|
|
Number of the port where the server listens for requests |
|
|
|
Name of the database server |
|
|
|
User name to be used for login |
|
|
|
Specifies the Oracle JDBC driver type. It can be either This is an Oracle-specific property. |
|
|
|
Specifies the URL of the database connect string.You can use this property in place of the standard 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.