Using URLs to set properties for a JDBC Connection
Where URLs are used
URLs -- uniform resource locators -- are tools for identifying and locating resources over a network. The JDBC specification makes general recommendations for the use of URLs within JDBC. We have implemented these recommendations in a way that is used consistently throughout all of our products, and that abides by the current URL guidelines (at www.w3.org).
With WebLogic products, you can use a URL to specify parameters needed to make a WebLogic JDBC Connection.
How WebLogic URLs are structured
Specifying a Connection with a Properties object and a URL
The WebLogic JDBC drivers use a java.utils.Properties object to set properties that are used to open a JDBC Connection between your client and the target database. The WebLogic JDBC drivers also use a URL, as described in the JDBC specification, to identify the JDBC driver. The Properties object and the URL are used as arguments for the DriverManager.getConnection() method or the Driver.connect() method.
Note: DriverManager.getConnection() is a synchronized method, which can cause your application to hang in certain situations. For this reason, BEA recommends that you use the Driver.connect method instead, as demonstrated in the code fragments in this document.
The usual process follows this model:
Properties dbprops = new Properties(); dbprops.put("user", "scott"); dbprops.put("password", "tiger"); dbprops.put("server", "DEMO");
The Properties object that contains the username, password, and servername for the two-tier connection becomes part of another Properties object that we use to set parameters for the multitier WebLogic JDBC connection.
Properties t3props = new Properties(); t3props.put("weblogic.t3", t3); t3props.put("weblogic.t3.dbprops", dbprops); t3props.put("weblogic.t3.driverClassName", "weblogic.jdbc.oci.Driver"); t3props.put("weblogic.t3.driverURL", "jdbc:weblogic:oracle");
All of the information for both the two-tier and multitier connections is then passed to the Driver when the JDBC Connection is instantiated by calling the Driver.connect() method. This method takes two arguments, a String URL and a java.util.Properties object.
Driver myDriver = (Driver) Class.forName("weblogic.jdbc.t3.Driver").newInstance(); Connection conn = Driver.connect("jdbc:weblogic:t3", t3props);
For documentation that describes this process for each of the WebLogic JDBC drivers, see WebLogic JDBC Options.
Specifying a WebLogic JDBC connection with a single URL
Some development environments (like Sybase's PowerJ) use the Properties object exclusively for username and database. That restriction means that you must use the URL passed as the first argument to the DriverManager.getConnection() method to set all of the other parameters required for a WebLogic JDBC connection, including the servername, as well as all of the weblogic.t3 properties.
For such environments, we allow you to supply all of the other information needed for a WebLogic JDBC Connection by constructing a long URL that is patterned after an RFC 1630-style query string.
Here is the syntax for WebLogic URLs. The property name is shown in bold, and a sample value follows it.
There are other optional properties that you may add to this list. For details on properties, see Setting properties for connecting in the Developers Guide.
Here is an example of specifying a URL for a connection to an Oracle database named DEMO, with a WebLogic Server running on port 7001 of a host "toyboat.toybox.com," with the cacheRows property set to 25. This example assumes that you have set "username" and "password" properties for access to the database with a Properties object. The characters "?" and "&" have special meanings in a URL and are set off here in red. For simplicity, the different parts of the URL are displayed in different lines; in reality, this URL is one long string.
jdbc:weblogic:t3? weblogic.t3.serverURL=t3://toyboat.bigbox.com:7001& weblogic.t3.driverClassName=weblogic.jdbc.oci.Driver& weblogic.t3.driverURL=jdbc:weblogic:oracle:DEMO& weblogic.t3.cacheRows=25
ShortcutsGiven certain pieces of information, we can infer other details that allow you to simplify the URL.
For example, you can supply more information first piece of the URL, the WebLogic JDBC driver URL, like database vendor and DBMS host, that negates the need for the weblogic.t3.driverURL, as shown here:
If you are using one of the drivers in WebLogic jDriver group, you can infer the class name of the driver from the first piece of the URL that we shortened in the example above, or from the property weblogic.t3.driverURL. We map the vendor name in either URL to a driver in the WebLogic jDriver group, as shown in this table:
jdbc:weblogic:t3:oracle:DEMO? weblogic.t3.serverURL=t3://toyboat.bigbox.com:7001& weblogic.t3.cacheRows=25
Quoting metacharacters in a URLURL syntax allows only a subset of the graphic printable characters of the US-ASCII coded character set, specifically the letters A-Z (both upper and lower case), the digits, and the characters $-_.+!*'()" may be used in a URL. Any other characters should be represented by a character triplet that is the character "%" followed by two hexadecimal digits ("0123456789ABCDEF") which form the hexadecimal representation of the character.
Some characters may be reserved by a URL scheme; those characters include ; / ? : @ = and &. These must always be encoded when used outside their reserved purpose in a URL.
The following characters are reserved in the WebLogic URL scheme. You must use a character triplet to represent these characters in a URL for anything other than a reserved purpose:
Using IDEs and wizards
You can also use URLs with IDEs -- integrated development environments or wizards -- like Sybase's PowerJ or Borland's JBuilder. If an IDE requires the fully qualified classname and a URL, here is how the classname for WebLogic's JDBC driver should be entered:
JDBC Driver: weblogic.jdbc.t3.Driver
The characters "?" and "&" have special meanings in a URL and are set off here in red. For simplicity, the different parts of the URL are displayed in different lines; in reality, this URL is one long string. Following is the URL for the PowerJ database wizard.
Data Source URL: jdbc:weblogic:t3? weblogic.t3.serverURL=t3://toyboat.bigbox.com:7001& weblogic.t3.driverClassName=weblogic.jdbc.oci.Driver& weblogic.t3.driverURL=jdbc:weblogic:oracle:DEMO& weblogic.t3.cacheRows=25
Copyright © 2000 BEA Systems, Inc. All rights reserved.