JDBC being core to most enterprise Java applications, I always try to keep myself up-to-date with JDBC and the changes in Oracle JDBC drivers. Like any casual readers I skipped many things in user guides and missed the JDBC URL changes until recently. Many of these changes were introduced in 9.2 JDBC drivers but the old style syntax was still documented in 9.2 JDBC Guide.
This change will impact you only if you follow a bad practice of hardcoding JDBC URLs in your source code . If you are using a J2EE container this requires just a change in the Data Sources configuration.
In the prior releases Oracle JDBC driver required the following syntax for the JDBC URL:
jdbc:oracle:<driver_type>:@hostname:<listener-port>:<SID>
Here is an example URL if I use THIN driver with database SID as db
jdbc:oracle:thin:@oc4j.us.oracle.com:1521:db
There is special THIN style Service name syntax supported with only THIN JDBC driver that was introduced in 10g JDBCdriver (This is one most Java developers will care)
jdbc:oracle:thin:@//host_name:port_number/service_name
Here is an example of an URL that uses THIN style syntax
jdbc:oracle:thin:scott/tiger@//myhost:1521/myservicename
The format for URL in 10g has been mandated to follow although this was introduced in 9.2 as follows: (The old style syntax has been removed from the 10g documentation)
jdbc:oracle:driver_type:[username/password]@database_specifier
Here is an example of the URL with the new convention using the THIN driver with an address list
jdbc:oracle:thin:@(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=localhost) (PORT=1521))
(CONNECT_DATA=(SERVICE_NAME= service_name)))"
Here is an example of the URL with the new convention using the THIN driver that has an address list with load balancing switched on:
jdbc:oracle:thin:@(DESCRIPTION=
(LOAD_BALANCE=on)
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=localhost) (PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=host2)(PORT=1521)))
(CONNECT_DATA=(SERVICE_NAME= service_name)))"
Here is an example URL that uses OCI driver in a cluster
jdbc:oracle:oci:@(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP) (HOST=cluster_alias)PORT=1521)) (CONNECT_DATA=(SERVICE_NAME=service_name)))"
The old style syntax is deprecated but still works and may be de-supported in future so it is recommended to use the new syntax for the URL.
There are many other formats that you can use, for details, please refer to Oracle JDBC Driver 10g Guide.
12:42:15 PM
|