< Prev - Examples - Next >

Scalar Types Returning A Transfer Object

Use Case

Fetch data from a single row.

Example Description

PL/SQL Procedure : SERVER_INFO
create or replace procedure server_info
(
  i_diff        in   number,
  o_date        out  date,
  o_timestamp   out  timestamp,
  o_instance    out  varchar2,
  o_db_version  out  number,
  o_db_release  out  number
)
is
begin
  o_date := sysdate + i_diff;
  o_timestamp := systimestamp - i_diff;
  select sys_context('USERENV','INSTANCE_NAME')
    into o_instance
    from dual;
  o_db_version := DBMS_DB_VERSION.VERSION;
  o_db_release := DBMS_DB_VERSION.RELEASE;
end server_info;
Java Transfer Object : ServerInfoTO.java
/*
 * This file is generated by PL/SQL Enterprise Workbench Connector Builder.
 * PL/SQL Enterprise Workbench Copyright (c) Jan Richter, Hamburg, Germany, 2015-2016. All rights reserved.
 *
 * THIS FILE IS NOT INTENDED TO BE MODIFIED - IT WILL BE OVERWRITTEN ON EVERY RUN OF THE CONNECTOR BUILDER
 */

package transferobject;

import java.io.Serializable;
import java.sql.Date;
import java.sql.Timestamp;

final public class ServerInfoTO implements Serializable {
  private static final long serialVersionUID = 1L;

  public Date oDate;
  public Timestamp oTimestamp;
  public String oInstance;
  public int oDbVersion;
  public int oDbRelease;
}
Java Calling Class : ServerInfo.java
package plsql_workbench_examples;

import factory.JavaEeRPCFactory;
import service.ServerInfoService;
import transferobject.ServerInfoTO;

public class ServerInfo {
  public static void main(String[] args) {
    try {
      int diff = 10;

      // get the service
      ServerInfoService service = JavaEeRPCFactory.getServerInfoService();

      // calling the stored procedure, receiving a transfer object
      ServerInfoTO info = service.call(diff);

      // print server information
      System.out.println("database date(+" + diff + "):" + info.oDate);
      System.out.println("database timestamp(-" + diff + "):" + info.oTimestamp);
      System.out.println("database instance name:" + info.oInstance);
      System.out.println("database version:" + info.oDbVersion + "." + info.oDbRelease);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}