BEA Logo BEA WebLogic Server Release 5.0

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

Using URLs to set properties for a JDBC Connection

Where URLs are used
How WebLogic URLs are structured
Specifying a Connection with a Properties object and a URL
Specifying a WebLogic JDBC Connection with a single URL
Quoting metacharacters in a URL
Using IDEs

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

With WebLogic products, you can use a URL to specify parameters needed to make a WebLogic JDBC Connection.

Top of the page

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:

  1. Construct a java.util.Properties object for specifying certain information like username and password.
  2. Call the Class.forName().newInstance() method with the classname of the JDBC driver to load it and cast it to a java.sql.Driver object.
  3. Create a connection with the Driver.connect() method, which takes two arguments, the URL of the JDBC driver and a set of properties.
Here is a working code snippet that illustrates creating the Properties object, calling the Class.forName().newInstance() method, and creating a Connection object:
  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.

jdbc:weblogic:t3 (with JDK 1.1)
First, set the URL for the WebLogic JDBC driver. (In technical terms, the URL of the WebLogic JDBC driver is the scheme of the URL.)

Please note that WebLogic no longer supports JDK 1.0.2.

The WebLogic JDBC driver URL should be followed by a question mark (?), after which follows a series of name-value pairs. Each name-value pair is separated by an ampersand (&). (The example shows these delimiting characters in a different color.) Arguments that come after the "?" are shown here in an arbitrary order, and can occur in the URL in any order.

Sets the URL of the WebLogic Server.

Sets the URL of the two-tier JDBC driver. The syntax should include the information that you would set as the "server" property. For example, jdbc:weblogic:oracle:DEMO indicates a WebLogic JDBC driver for an Oracle database on the host "DEMO".

Sets the class name of the two-tier JDBC driver. Note that class names are always indicated as the full package name of the class, in dot-notation format.

Sets the rows to be cached on the WebLogic Server.

Sets the connection pool ID. This ID must be registered in the file. If you use a JDBC connection from a connection pool, other information in the URL is unnecessary. For more information, read up on Using connection pools in the Developers Guide, Using WebLogic JDBC.

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 "," 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.



Given 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:

rather than:

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:

    URL Inferred driver
    jdbc:weblogic:oracle weblogic.jdbc.oci.Driver
    jdbc:weblogic:mssqlserver4 weblogic.jdbc.mssqlserver4.Driver
    jdbc:weblogic:informix4 weblogic.jdbc.informix4.Driver
These shortcuts together reduce the URL used in the example to the following:

Top of the page

Quoting metacharacters in a URL

URL 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:

  • %26 (&)
  • %3D (=)
  • %3F (?)
  • %2F (/)
  • %3A (:)

Top of the page

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:

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:


Copyright © 2000 BEA Systems, Inc. All rights reserved.
Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.
Last updated 01/13/2000