`
BurningLuffy.DW
  • 浏览: 1736 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

Summary of Oracle Java Stored Procedure

阅读更多

 

1. Overview of Oracle Java Stored Procedure

Java is an object-oriented programming language efficient for application-level programs. Oracle provides all types of JDBC drivers and enhances database access from Java applications. Java Stored Procedures are portable and secure in terms of access control, and allow non-Java and legacy applications to transparently invoke Java.

Stored procedures are Java methods published to SQL and stored in the database for general use. To publish Java methods, you write call specifications, which map Java method names, parameter types, and return types to their SQL counterparts.

When called by client applications, a stored procedure can accept arguments, reference Java classes, and return Java result values. Figure 1-1 shows a stored procedure being called by various applications.

 


 

2. Java Stored Procedure Configuration

To configure the database to run Java stored procedures, you must decide on which of the following modes the database should run:

■ Dedicated server mode

You must configure the database and clients in dedicated server mode using Oracle Net Services connections.

■ Shared server mode

You must configure the server for shared server mode with the DISPATCHERS parameter.

Java, SQL, or PL/SQL clients, which run Java stored procedures on the server, connect to the database over an Oracle Net Services connection.

3. Java Stored Procedures Steps

You can run Java stored procedures in the same way as PL/SQL stored procedures. Normally, a call to a Java stored procedure is a result of database manipulation, because it is usually the result of a trigger or SQL DML call. To call a Java stored procedure, you must publish it through a call specification.

Before you can call Java stored procedures, you must load them into the Oracle Database instance and publish them to SQL. Loading and publishing are separate tasks. Many Java classes, which are referenced only by other Java classes, are never published.

To load Java stored procedures automatically, you can use the loadjava command-line utility. It loads Java source, class, and resource files into a system-generated database table, and then uses the SQL CREATE JAVA {SOURCE | CLASS | RESOURCE} statement to load the Java files into the Oracle Database instance. You can upload Java files from file systems, popular Java IDEs, intranets, or the Internet.

The following steps are involved in creating, loading, and calling Java stored procedures:

 

Step 1: Create or Reuse the Java Classes

import java.math.BigDecimal;

 

public class Paymaster {

                public static BigDecimal wages(BigDecimal  sal, BigDecimal comm) throws java.sql.SQLException {

                                BigDecimal pay = sal;

                                if (comm != null)

                                                pay = pay.add(comm);

                                return pay;

                }

}

 

Save the class as Oscar.java. Using a Java compiler(For Oracle 11g, the version of Java should be 1.5), compile the .java file on your client system, as follows:

javac Oscar.java

The compiler outputs a Java binary file, in this case, Oscar.class.

In a call specification, the corresponding SQL and Java parameters and function results must have compatible data types. Table 1–1 lists the legal data type mappings. Oracle Database converts between the SQL types and Java classes automatically.

Table 1–1 Legal Data Type Mappings SQL Type Java Class

CHAR, LONG, VARCHAR2   oracle.sql.CHAR

java.lang.String

java.sql.Date

java.sql.Time

java.sql.Timestamp

java.lang.Byte

java.lang.Short

java.lang.Integer

java.lang.Long

java.lang.Float

java.lang.Double

java.math.BigDecimal

byte, short, int, long, float, double

DATE                 oracle.sql.DATE

java.sql.Date

java.sql.Time

java.sql.Timestamp

java.lang.String

NUMBER               oracle.sql.NUMBER

java.lang.Byte

java.lang.Short

java.lang.Integer

java.lang.Long

java.lang.Float

java.lang.Double

java.math.BigDecimal

byte, short, int, long, float, double

OPAQUE               oracle.sql.OPAQUE

RAW, LONG RAW         oracle.sql.RAW

byte[]

ROWID                oracle.sql.CHAR

oracle.sql.ROWID

java.lang.String

BFILE                oracle.sql.BFILE

BLOB                 oracle.sql.BLOB

oracle.jdbc2.Blob

CLOB, NCLOB oracle.sql.CLOB

oracle.jdbc2.Clob

OBJECT               oracle.sql.STRUCT

Object types                            java.sql.Struct

java.sql.SqlData

oracle.sql.ORAData

REF                  oracle.sql.REF

Reference types                       java.sql.Ref

oracle.sql.ORAData

TABLE, VARRAY         oracle.sql.ARRAY

Nested table types                                  

and VARRAY types oracle.sql.ORAData

java.sql.Array

any of the preceding SQL   oracle.sql.CustomDatum

types                                        oracle.sql.Datum

 

Step 2: Load and Resolve the Java Classes

Using the loadjava utility, you can load Java source, class, and resource files into an Oracle Database instance, where they are stored as Java schema objects. You can run loadjava from the command line or from an application, and you can specify several options including a resolver.


Step 3: Publish the Java Classes


 

Step 4: Call the Stored Procedures

 


 

More introductions could be found in Oracle Database Java Developer’s Guide.pdf 

 

  • 大小: 17.5 KB
  • 大小: 944 Bytes
  • 大小: 26.1 KB
  • 大小: 32.2 KB
分享到:
评论

相关推荐

    存储过程(Stored Procedure)

    ### 存储过程(Stored Procedure)详解 #### 一、存储过程的概念与作用 存储过程是一种预先编写并编译好的SQL语句集合,通常用于实现特定的数据库操作或逻辑处理。存储过程存储在数据库服务器中,用户可以通过指定...

    Oracle9i Java Stored Procedures Developer’s Guide Release 2 (9.2

    "Oracle9i Java Stored Procedures Developer’s Guide Release 2 (9.2)" Oracle9i Java Stored Procedures Developer’s Guide Release 2 (9.2)是Oracle Corporation发布的一份开发者指南,旨在帮助开发者使用Java...

    学习使用存储过程(Stored Procedure)

    ### 学习使用存储过程(Stored Procedure) 在IT领域中,存储过程(Stored Procedure)是一项重要的技术,尤其对于从事Web开发尤其是ASP编程的开发者来说,掌握如何使用存储过程至关重要。存储过程是一种预先编译并...

    Using Informatica Stored Procedure Transformation

    在数据集成领域,Informatica是一个强大的企业级ETL(提取、转换、加载)工具,而“使用Informatica存储过程转换”是它的一项重要功能。存储过程转换允许用户通过Informatica执行预先在数据库中构建的存储过程,从而...

    Oracle8i Java Stored Procedures Developer’s Guide Release 2 (8.1

    Oracle8i Java Stored Procedures Developer’s Guide Release 2 (8.1.6) 以下是根据给定文件信息生成的相关知识点: Oracle8i Java存储过程 Oracle8i Java存储过程是一种将Java程序集成到Oracle数据库中的机制。...

    MySQL Stored Procedure Programming

    The implementation of stored procedures in MySQL 5.0 ... This book, destined to be the bible of stored procedure development, is a resource that no real MySQL programmer can afford to do without.

    解决OracleRAC集群下创建SDE时报Stored procedures错误问题.docx

    在Oracle RAC(Real Application Clusters)环境下,安装和配置ArcGIS Desktop的SDE(Spatial Database Extensions)数据库连接时,可能会遇到"Stored procedures"错误。这个问题通常与Oracle RAC的特性有关,即其...

    mysql存储过程编程 MySQL.Stored.Procedure.Programming

    mysql存储过程方面的圣经,以通俗的示例方法讲述mysql存储过程的深奥内容,In MySQL Stored Procedure Programming, they put that hard-won experience to good use. Packed with code examples and covering ...

    一个基于ADO.NET+COBOL+Stored Procedure的程序例子代码

    Stored Procedure是SQL Server数据库中预编译的SQL语句集合,它可以执行一系列复杂的数据库操作,如查询、插入、更新和删除数据。使用Stored Procedure有诸多优点,包括提高性能、减少网络流量、增强安全性以及提供...

    oracle调用java包

    通过Java存根(Java Stored Procedures, JSP),我们可以把Java方法封装为数据库过程,然后在PL/SQL中调用。首先,我们需要确保Oracle数据库已经启用了Java支持: 1. 检查Java环境: 使用以下SQL查询检查Oracle...

    Oracle 9i Supplied Java Packages Reference Release 2 (9.2)

    这些 Java 包包括了 Oracle 供给的各种工具和类库,例如 Oracle JDBC 驱动程序、Oracle SQLJ translator、Oracle Java stored procedures 等。 安装和配置 Oracle 供给的 Java 包 要使用 Oracle 供给的 Java 包,...

    MySql存储过程编程.chm

    MySQL Stored Procedure Programming Advance Praise for MySQL Stored Procedure Programming Preface Objectives of This Book Structure of This Book What This Book Does Not Cover Conventions ...

    sybase stored procedure

    在 Sybase 中,存储过程分为两种类型:用户定义的存储过程(User-Defined Stored Procedures)和系统存储过程(System Stored Procedures)。用户定义的存储过程是由开发者创建的,可以根据业务需求进行定制。系统...

    A tool to generate class files to implement stored procedure

    标题中的"A tool to generate class files to implement stored procedure"指的是一个软件工具,它的主要功能是自动生成Java类文件,这些类文件被设计用来实现数据库中的存储过程。存储过程是在数据库中预编译的SQL...

    一个基于C#实现的后台运行 any stored procedure 的类库源码程序

    标题中的“一个基于C#实现的后台运行 any stored procedure 的类库源码程序”表明这是一个C#编程项目,它的核心功能是能够在后台执行SQL Server的存储过程(stored procedure)。存储过程是预编译的SQL语句集合,...

    DB2 Stored Procedure 存储过程教程

    DB2存储过程是数据库管理中的一个重要概念,它是一组为了完成特定功能的SQL语句集,可以在数据库中预先编译并存储。这个教程是专为初学者设计的,旨在帮助快速掌握DB2存储过程的创建、调用以及相关概念。...

    oracle10g-java lib

    总结,Oracle 10g的Java库不仅为开发者提供了直接在数据库内运行Java代码的能力,还支持了各种Java相关的开发和管理功能,如JDBC、Java Stored Procedures、JVM等,使得Java开发者能够更高效地利用Oracle数据库进行...

    mysql stored procedure programming PDF

    涉及的关键字包括CREATE PROCEDURE、CALL、ALTER PROCEDURE、DROP PROCEDURE等。 3. 参数和变量:学习存储过程中的输入参数、输出参数以及局部变量的使用和声明。参数允许存储过程接收外部的输入值,而局部变量则...

Global site tag (gtag.js) - Google Analytics