HomeSitemapSearchDownload


Products
Successes
Developer info

News
About BEA WebXpress

Tech infoOverviewGetting startedDocumentationCustomer Support

WebLogic JDBC examples

At the core of WebLogic's pure Java technology is the integrated WebLogicTM multitier architecture, a key element in client-network computing. Applications using WebLogic share access to a set of cooperative server facilities, such as security, name and directory services, application-wide logging, a graphical management console for instrumentation and configuration, and scarce resource management. Multiple WebLogic Servers can be configured as a WebLogic Cluster -- a scalable, loosely-coupled cluster in one or more locations over a multitier heterogeneous distributed environment -- for load balancing and distributed processing.

WebLogic/JDBC provides JDBC database connectivity services within WebLogic's multitier WebLogic framework. With WebLogic JDBC, the WebLogic Server acts as a distributed server managing database interaction between T3Clients and one or more heterogeneous databases. You can use dbKona on top of WebLogic JDBC to provide a set of database objects that are more flexible and more abstract than the low-level JDBC interface.

Other WebLogic services -- like a WebLogic Events for realtime event management and notification, and WebLogic RMI and WebLogic Enterprise JavaBeans for distributed computing -- also operate within the WebLogic Server.

The examples on this page show how WebLogic JDBC is used within the WebLogic Server to create interactive applets with data from a remote DBMS. These examples use Java JDK 1.1 applets that work with the Netscape 3.0 or Microsoft IE 3.0.2 browsers, or later. Applet use in browsers early than Netscape 3.0 or Microsoft IE 3.0.2 is not supported.

Using an ODBC driver with WebLogic JDBC

In this example we use an ODBC driver with the JDBC-ODBC bridge to connect to an Oracle database and build a ResultSet from a query. This example prints out the version and name of the ODBC driver in use.

Top of the page

Using a cached JDBC Connection to log in and make a query

Each T3Client has its own Workspace within the WebLogic Server; the lifetime of a T3Client's workspace, like all of the T3Client's resources on the WebLogic Server, can be controlled by setting the T3Client's soft disconnect timeout to never. Then the T3Client can disconnect from the WebLogic Server, open a new connection to the WebLogic Server at some time in the future with the name or ID of the Workspace created in the previous session, and return to its Workspace.

One of the objects that the T3Client can save in its Workspace is a JDBC Connection. Once a connection has been created and named, you can return to the same open connection to the DBMS over and over again, without having to supply any further parameters for access to the database.

This example shows how to create a reusable JDBC Connection, save it into a T3Client's Workspace, and return to the Workspace and the connection.

Caching objects on a WebLogic Server

Not only can you cache login sessions, you can also cache any arbitrary object on the WebLogic Server in a Workspace. Objects are stored and retrieved by key. Here's a simple example that shows store and fetch for an arbitrary value, which we call "cookie".


Top of the page

Using a connection pool

You can create a pool of JDBC connections by entering the proper registration into your weblogic.properties file. Then, in your program (like in this example) all you'll need to specify are properties for the connection between the client and the WebLogic Server. All of the parameters for the connection between the WebLogic Server and the DBMS -- including username and password for access to the database -- are supplied with the Connection and are effectively obscured from the T3Client program. If you use a connection pool with WebLogic JDBC and dbKona, your database code may be completely free of any database-specifics at all, making it possible to switch among various databases with the same program by simply changing a configuration parameter.

The registration in the properties file for this connection pool is:

weblogic.jdbc.connectionPool.eng=\
       url=jdbc:weblogic:oracle,\
       driver=weblogic.jdbc.oci.Driver,\
       initialCapacity=4,\
       maxCapacity=10,\
       capacityIncrement=2,\
       props=user=SCOTT;password=tiger;server=DEMO
weblogic.allow.reserve.weblogic.jdbc.connectionPool.eng=\
       guest,joe,jill

The second property sets up an access control list for the connection pool. Note that the T3Client we create in this example must be associated with a T3User found in the access control list. But "guest" is included in the list of allowable T3Users, and a T3Client created without a T3User -- like the one in the sample code -- is automatically created as the default T3User "guest."

Top of the page

Using a startup class to store a dbKona DataSet for T3Client use

You can write a startup class for the WebLogic Server that can do most anything as the WebLogic Server starts up. Startup classes are automatically loaded and executed when the WebLogic Server starts up so that you can use them to perform functions that need to run when a WebLogic Server-based application is launched.

In this example, we illustrate how you can use a startup class to query a database and populate a dbKona DataSet that is saved into the system workspace on the Weblogic Server. That allows one or more T3Clients to log in and use the same dbKona DataSet over an extended period of time, without having to query the DBMS again. None of the clients needs to execute a query, or in fact have any information about access to the DBMS.

First take a look at how the connection is made and the DataSet is stored in the startup() method for this class. Then check how the DataSet is fetched by a T3Client in the main() of this class.

Using simple form applications

These examples demonstrate simple Java form-based applications. We've used AWT to build a simple form that lets you browse entries in a phone book. It shows a practical application for an applet accessing data via a WebLogic Server; we use a cached login if one is available.

More code examples

Copyright
© 1996-1999 by BEA WebXpress, Inc.
All Rights Reserved.

Last updated 12/29/1998