gpt4 book ai didi

java - Oracle DB 12c/SQL Developer 中 Java 目录的用途是什么?

转载 作者:行者123 更新时间:2023-12-01 19:50:45 27 4
gpt4 key购买 nike

使用 Oracle SQL Developer 时,我注意到它有一个“Java”目录(如图所示)。

SQL Developer - Java Directory

我假设它的目的是在数据库中存储 Java 源/类代码。我还假设这意味着 Java 代码可以从 DBMS 内执行。我查看了帮助文档来寻找这方面的证据,但只在 Java Sources 下找到了以下内容:

Java sources can be created and managed in the database.

我不太清楚以下任何一项(除 1 之外)是否为真:

  1. 可以将 Java 源代码/类存储在数据库中。
  2. Java 代码/应用程序可以在 RDBMS 环境内运行,而不仅仅是在外部运行。
  3. DBMS 的插件/扩展/附加模块可以用 Java 编写。

陈述 2 和 3 哪一个(如果有)是正确的?如果该目录不仅仅用于存储,那么该目录的用途是什么?将源代码存储在数据库中而不是使用版本控制工具(例如 git)是否有优势?

最佳答案

感谢 Alex Poole 提供 Oracle 文档的链接,其中说明如下:

来自 Oracle 的 "Using Java"文档:

You can write and load Java applications within the database because it is a safe language with a lot of security features.

[...] clients call Java stored procedures the same way they call PL/SQL stored procedures.

来自 Oracle 的 Java Programming in Oracle Database文档:

Java stored procedures as the Java equivalent and companion for PL/SQL: Java stored procedures are tightly integrated with PL/SQL. You can call Java stored procedures from PL/SQL packages and PL/SQL procedures from Java stored procedures.

Java stored procedures are Java programs written and deployed on a server and run from the server, exactly like a PL/SQL stored procedure. You invoke it directly with products like SQL*Plus, or indirectly with a trigger. You can access it from any Oracle Net client, such as OCI and PRO*, or JDBC or SQLJ.

In addition, you can use Java to develop powerful, server-side programs, which can be independent of PL/SQL. Oracle Database provides a complete implementation of the standard Java programming language and a fully compliant JVM.

You can call existing PL/SQL programs from Java and Java programs from PL/SQL. This solution protects and leverages your PL/SQL and Java code and opens up the advantages and opportunities of Java-based Internet computing.

Oracle Database offers two different Java APIs for accessing SQL data, JDBC and SQLJ. Both these APIs are available on the client, and the JDBC API is also available on the server. As a result, you can deploy your applications on the client and server.

来自"Stored Procedures and Runtime Contexts"文档:

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.

You can run Java stored procedures in the same way as PL/SQL stored procedures. Usually, 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.

这让我明白:

  1. Java 目录是数据库本身的一部分,而不是 SQL Developer。
  2. 此目录的目的用于存储通过可调用函数定义存储过程(及其辅助方法)的 Java 类,如下所示:1<

public class Oscar {
// return a quotation from Oscar Wilde
public static String quote() {
return "I can resist everything except temptation.";
}
}
<pre>CREATE FUNCTION oscar_quote RETURN VARCHAR2 AS LANGUAGE JAVA
NAME 'Oscar.quote() return java.lang.String';
VARIABLE theQuote VARCHAR2(50);
CALL oscar_quote() INTO :theQuote;
PRINT theQuote;</pre>

如果程序使用标准 JVM 外部的库,首先需要通过 loadjava command-line utility 加载它们。 。例如:

loadjava -user USERNAME/password@sid -resolve /path/to/externalLib.jar
<小时/>
  1. Running Java Stored Procedures

关于java - Oracle DB 12c/SQL Developer 中 Java 目录的用途是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51374930/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com