Reputation: 2134
When using Oracle SQL Developer, I noticed that it has a 'Java' Directory (as in the image).
I assumed that the purpose of it is for storing Java source/class code in the DB. I also assumed that means Java code can be executed from within the DBMS. I looked at the help documentation for evidence of this, but only found the following, under Java Sources:
Java sources can be created and managed in the database.
It's not really clear to me if any of the following (other than 1) are true:
Which (if any) of statements 2 and 3 is true? What is the purpose of that directory if not only for storage? is there an advantage to storing source code in the DB instead of using a version control tool such as git?
Upvotes: 0
Views: 1034
Reputation: 2134
Thank you to Alex Poole for links to the Oracle documentation, which states the following:
From Oracle's "Using Java" documentation:
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.
From Oracle's Java Programming in Oracle Database documentation:
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.
From the "Stored Procedures and Runtime Contexts" documentation:
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.
This leads me to the understanding that:
public class Oscar {
// return a quotation from Oscar Wilde
public static String quote() {
return "I can resist everything except temptation.";
}
}
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;
If the program uses libraries external to the standard JVM, they first need to be loaded through the loadjava
command-line utility. For example:
loadjava -user USERNAME/password@sid -resolve /path/to/externalLib.jar
Upvotes: 3
Reputation: 5063
The Oracle Database allows for calling Java code from PL/SQL - details here. Any Java code uploaded to the database will show in SQL Developer in Java directory.
Upvotes: 1