Weblogic JDBC

At the end of this chapter you will be able to:

  • Describe the high-level architecture of JDBC
  • List the four driver types, and those provide by WLS
  • Describe and configure Data Sources
  • Use the Administration Console to manage JDBC resources

Overview of JDBC

What Is JDBC?

  • JDBC is an API for uniformly accessing databases.

22

  • JDBC provides:

    • Platform independent access to databases
    • Location transparency
    • Transparency to proprietary database issues
    • Support for both two-tier and multi-tier models for database access

JDBC Architecture

23

JDBC Drivers:

Type 1 Driver

  • The Type 1 driver:

    • Is a JDBC-ODBC bridge
    • Usually, runs on Windows
    • Requires ODBC driver to be installed on client machine

24

Type 2 Drivers

  • The Type 2 driver:

    • Requires a native driver to be already installed on the client machine
    • The driver converts JDBC calls to native API calls of the database.

25

Type 3 Drivers

  • A network server can apply several techniques to boost performance:

    • Connection Pooling
    • Load management

26

27

Type 4 Drivers

  • Type 4 drivers are ‘all-Java’ driver implementations that do not require client side configuration.

28

Two-Tier Architecture

  • In the two-tier model, a Java application communicates directly with the DBMS.
  • A JDBC driver is needed that can communicate directly with the DBMS.
  • This is a client/server configuration.

29

Multi-Tier Architecture

  • In the multi-tier model, commands are sent to a "middle tier" of services, which then sends the commands to the DBMS.
  • The DBMS processes the commands and sends the results back to the middle tier, which then sends them to the client.

 30

Choosing the Correct Driver

  • Choosing the correct driver can have a significant impact on performance.
  • For two-tier applications use the type 1, 2 or 4 driver specific to the DBMS you are using.
  • For multi-tier applications use:

    • Data Source lookup in a client class
    • A type 1, 2 or 4 drivers on the server, specific to the DBMS you are using
    • XA driver where transaction support is required

Data Sources:

What Is a Data Source?

  • A Data Source object provides a way for a JDBC client to obtain a database connection from a connection pool.
  • A Data Source:

    • Is stored in the WLS JNDI tree
    • Can support transactions
    • Is associated with a connection pool

What Is a Connection Pool?

  • A connection pool is a group of ready-to-use database connections associated with a Data Source.
  • Connection pools:

    • Are created at WebLogic Server startup
    • Can be administered using the Administration Console
    • Can be dynamically resized to accommodate increasing load

Benefits of Data Sources and Connection Pools

  • Some advantages of this approach are:

    • Time and overhead are saved by using an existing database connection
    • Connection information is managed in one location in the Administration Console
    • The number of connections to a database can be controlled
    • The DBMS can be changed without the application developer having to modify underlying code

  • A connection pool allows an application to “borrow” a DBMS connection.

JDBC Data Source Architecture

31

Modular Configuration and Deployment of JDBC Resources

  • JDBC configurations in WLS are stored in XML documents:

    • All JDBC configurations must conform to the new weblogic-jdbc.xsd schema.
    • IDEs and other tools can validate JDBC modules based on the schema.

  • You create and manage JDBC resources either as system modules or as application modules.
  • JDBC application modules are a WLS-specific extension of J2EE modules and can be deployed either within a J2EE application or as stand-alone modules.

How Data Sources Are Used

  • A client retrieves a Data Source through JNDI lookup and uses it to obtain a database connection.

32

Creating a JDBC Data Source…

33

Creating a Data Source: Properties

34

Creating a Data Source: XA Options

35

Creating a Data Source: ConnectionProperties

36

Creating a Data Source: Test Database Connections & Select Targets:

37

Configuring a Connection Pool…

38

39

40

Connection Pool Checklist

  • You can modify a connection pool after the Data Source has been created
  • Before modifying a connection pool, you should understand:

    • The JDBC URL of the database
    • The connection properties used to authenticate a user or optionally configure the driver

  • Ask your DBA for:

    • The maximum number of connections your application will be allowed.

JDBC URLs

  • Database locations are specified using a JDBC Uniform Resource Locator (URL).

41

Examples:

42

Multi Data Sources…

  • Multi Data Source:

    • It is an abstraction around a group of data sources
    • Determines which data source to use to satisfy the request depending on the algorithm selected in the multi data source configuration:

      • Load balancing Or • Failover

    • Are bound to the JNDI tree

  • XA Support for Multi Data Sources

    • The WLS JDBC supports using Multi Data Sources in XA transactions.
    • You can configure the data sources contained within the Multi Data Source to use XA JDBC drivers.

43

Monitoring & Testing Data Sources

Monitoring Data Sources: Statistics

  • The Administration console provides two types of data source monitoring: statistics and testing.

44

Monitoring Data Sources: Testing

  • The Administration console provides a mechanism for manually testing individual data sources.

45

Summary: 

In this chapter we discussed:

  • JDBC high-level architecture
  • WebLogic Server provided JDBC driver types
  • Data Source definition and workings
  • Connection pool definition and workings
  • Managing JDBC resources with the Administration Console.

Check out our Related Courses

Weblogic Tutorials

Introduction to Clustering Weblogic

Weblogic Server Admin Training in Hyderabad

Oracle Weblogic Server Installation