Skip Headers

Oracle® Database Java Developer's Guide
10g Release 1 (10.1)

Part Number B12021-01
Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Index
Go to Master Index
Master Index
Go to Feedback page

Go to previous page
Go to next page
View PDF

Database Web Services

This chapter provides and overview of database Web services and discusses how to call out to an existing Web service. For information on how to create a Web service, see the Oracle9iAS Web Services Developer's Guide and For more information on database Web services, see

This chapter covers the following topics:

Database Web Services

Web services technology enables application-to-application interaction over the Web - regardless of platform, language, or data formats. The key ingredients, including XML, SOAP, WSDL, and UDDI, have been adopted across the entire software industry. Web services technology usually refers to services implemented and deployed in middle-tier application servers. However, in heterogeneous and disconnected environments, there is an increasing need to access stored procedures as well as data and metadata, through Web services interfaces. Database Web services technology is a database approach to Web services.

It works in two directions:

Turning the Oracle database into a Web service provider leverages investment in Java stored procedures, PL/SQL packages, pre-defined SQL queries and DML. Conversely, consuming external Web services from the database itself, together with integration with the SQL engine, enables Enterprise Information Integration.

This chapter focuses on the advantages of opening up the Oracle Database, through PL/SQL packages and Java classes deployed within the database, to the world of Web services, using the Oracle Application Server and the Oracle database.

Refer to the Oracle9iAS Web Services Developer's Guide for information on:

This chapter also provides a general road map for database Web services, mapping out Web services support for additional database capabilities, such as SQL queries, DML statements, and Java Stored Procedures--through synchronous invocation.

See the Oracle9iAS Web Services Developer's Guide on how to create Web services and invoke them from clients. This chapter covers how to call out to Web services from within the database and how a Web service can call in to the database.

Using the Database as Service Provider for Web Services

Web Services uses industry-standard mechanisms to provide easy access to remote content and applications, regardless of the provider's platform, location, implementation, or data format. Client applications can query and retrieve data from Oracle databases and invoke stored procedures using standard web service protocols. There is no dependency on Oracle-specific database connectivity protocols. This approach is highly beneficial in heterogeneous, distributed, and non-connected environments.

You can call into the database from a Web Service, using the database as a service provider. This allows you to leverage existing or new SQL, PL/SQL, Java stored procedures, or Java classes within an Oracle database. You can access and manipulate database tables from a Web service client.

Use JPublisher to generate Java wrappers that correspond to database operations, then deploy the wrappers as Web services in Oracle AS. Figure 12-1 demonstrates how you use JPublisher to publish PL/SQL packages, SQL objects, collections, and packages as Java classes. Once published, these objects can be accessed by any Web service through an OC4J Web services servlet.

Figure 12-1 Web Services Calling In to the Database

Text description of webserva.gif follows.

Text description of the illustration webserva.gif

How to Use

For directions on how to use JPublisher to publish your PL/SQL or SQL objects, collections or packages as Java classes, see the "What JPublisher Can Publish" section in the "Introduction to JPublisher" chapter of the Oracle Database JPublisher User's Guide.

See the Oracle9iAS Web Services Developer's Guide for more information on creating and using Web services.

Features of the Database as a Web Service Provider

Using the database as a Web Service provider offers the following features:

JPublisher Support for Web Services Call-Ins to the Database

The following JPublisher features support Web services call-ins to code running in Oracle Database. Refer to the JPublisher Oracle Database JPublisher User's Guide for complete information.

Using the Database as Service Consumer for Web Services

You can extend a relational database's storage, indexing, and searching capabilities to include semistructured and nonstructured data (including Web Services) in addition to enabling federated data. By calling Web Services, the database can track, aggregate, refresh, and query dynamic data produced on-demand, such as stock prices, currency exchange rates, and weather information.

An example of using the database as a service consumer would be to call external Web Services from a predefined database job in order to obtain inventory information from multiple suppliers, then update your local inventory database. Another example is that of a Web Crawler: a database job can be scheduled to collate product and price information from a number of sources.

How to Use

The Web services client code is written in SQL, PL/SQL, or Java to run inside the database, which then invokes the external Web service. Figure 12-2 demonstrates how you can call out to a Web service from a Java client within the database by using one of the following methods:

Which method to use depends on if you want to execute from SQL or PL/SQL or from Java classes.

To call out to any Web service through PL/SQL, use the UTL_DBWS PL/SQL package. This package essentially uses the same APIs as the DII classes. See the PL/SQL Packages and Types Reference for a full description of this package.

You can use a Web Services Data Source to process the results from any Web service request as if it was a real database table.

Figure 12-2 Calling Web Services From Within the Database

Text description of webservi.gif follows.

Text description of the illustration webservi.gif

Web Service Data Sources (Virtual Table Support)

To access data (returned from single or multiple Web service invocations) through a database table, create a virtual table through a Web service data source. This table function allows you to query a set of returned rows as though it were a table.

The client invokes a Web service and the results are stored in a virtual table in the database. You can pass result sets from function to function, allowing you to set up a sequence of transformation without a table holding intermediate results. To reduce memory usage, you can return the result set rows a few at a time within a function.

By using Web services with the table function, you can manipulate a range of input values (from single or multiple Web services) as a real table. In the following example, the inner SELECT creates rows whose columns are used as arguments for invoking the CALL_WS Web service call-out. The table expression could be used in other SQL queries, for constructing views, and so on.

SELECT <some-columns>
s FROM <some_table>))),

Figure 12-3 Storing Results from Request in a Virtual Table

Text description of storing_.gif follows.

Text description of the illustration storing_.gif

Features of the Database as a Web Service Consumer

Using the database as a Web Service consumer offers the following features:

Installation Requirements

Before generating any stubs or call specs, you must install the UTL_DBWS package in the database. This package includes both the Java and PL/SQL implementation necessary for facilitating the Web services functionality within the database.

Use the following script to install the Web Services Client Library:


To remove the Web Services Client Library at a later time, use the following script:


JPublisher Generation Overview

JPublisher can accept receive the WSDL from the Web Service and create the static java, proxy class, or PL/SQL call spec, as shown in Figure 12-4.

Figure 12-4 Creating Web Services Callout Stubs

Text description of creating.gif follows.

Text description of the illustration creating.gif

This support is created through the following JPublisher key options:

See the "Additional Features" chapter in the Oracle Database JPublisher User's Guide for more information on how to use JPublisher.

Adjusting the Mapping of SQL Types

Although Oracle Application Server does not currently support LOB types, XMLTYPE, REF CURSORS, and OUT/IN OUT arguments (they will be addressed in future releases), you can use an alternative approach to expose PL/SQL methods and SQL types as Web services.

You can change JPublisher's default behavior to generate code that uses a user-provided subclass. For example, if you have a PL/SQL method that returns a REF CURSOR, JPublisher automatically maps the return type to java.sql.ResultSet. However, this ResultSet type cannot be published as a Web service. To solve this, simply create a new method that can return the result set in a Web service-supported format, such as:

public String [] readRefCursorArray(String arg1, Integer arg2)
  {java.sql.ResultSet rs = getRefCursor(arg1,arg2);
    ... create a String[] from rs and return it... }

Then create an interface that contains the exact methods to publish. You can use JPublisher to easily accomplish this mapping by using the following:

jpub -sql=MYAPP:MyAppBase:MyApp#MyAppInterf...


After translating the code for your application, archive all the class files into a single JAR file and use the Web Services Assembler to create a deployable Web service EAR file. Refer to Oracle Database JPublisher User's Guide for more information.

Using the Native Java Interface

Oracle Database 10g introduces the native Java interface--new features for calls to server-side Java code. It is a simplified application integration: client-side (and middle-tier) Java applications can directly invoke Java in database without the need for defining a PL/SQL wrapper. Uses server-side Java class reflection capability.

In previous releases, calling Java stored procedures and functions from a database client required JDBC calls to associated PL/SQL wrappers. Each wrapper had to be manually published with a SQL signature and a Java implementation. This had the following disadvantages:

The JPublisher -java option provides functionality to avoid these disadvantages. To remedy the deficiencies of JDBC calls to associated PL/SQL wrappers, the -java option makes convenient use of an API for direct invocation of static Java methods. This functionality is also useful for Web services.

The functionality of the -java option mirrors that of the -sql option, creating a client-side Java stub class to access a server-side Java class, as opposed to creating a client-side Java class to access a server-side SQL object or PL/SQL package. The client-side stub class uses JPublisher code that mirrors the server-side class and includes the following features:

At runtime, the stub class is instantiated with a JDBC connection. Calls to its methods result in calls to the corresponding methods of the server-side class. Any Java types used in these published methods must be primitive or serializable.

As an example, assume you want to call the following method in the server:

public String oracle.sqlj.checker.JdbcVersion.to_string();

Use the following -java setting: