SlideShare une entreprise Scribd logo
1  sur  31
Writing Java Stored Procedures
with Oracle RDBMS
Martin Toshev
Who am I
Software consultant (CoffeeCupConsulting)
BG JUG board member (http://jug.bg)
OpenJDK and Oracle RDBMS enthusiast
Twitter: @martin_fmi
Work in progress …
Agenda
• PL/SQL vs Java Stored Procedures
• Writing Java Stored Procedures
• Managing Java Stored Procedures
• New features in Oracle Database 12c
PL/SQL vs Java Stored Procedures
PL/SQL vs Java Stored Procedures
• Both PL/SQL and Java stored procedures are executed
directly on the RDBMS
• Both PL/SQL and Java stored procedures can be
recompiled dynamically when source code changes
• Easier migration of Java stored procedures to/from the
application tier
PL/SQL vs Java Stored Procedures
• The PL/SQL Virtual Machine (PVM) is the database
component that executes the PL/SQL bytecode (lower
lever representation of the PL/SQL code that is generated
from the PL/SQL compiler)
• PVM is written in C
PL/SQL vs Java Stored Procedures
• Java procedures are executed from a JVM (Java Virtual
Machine) process running inside the Oracle RDBMS:
Oracle
DB
Oracle
RDBMS
PL/SQL JVM
Java
method
PL/SQL vs Java Stored Procedures
• Since the Oracle JVM is embedded in the database this
introduces a number of new concepts:
– Oracle JVM process that runs within an Oracle database session
– classloader that loads classes from the database
– no notion of main() method
– loading of system classes from the SYS schema (where they are stored)
PL/SQL vs Java Stored Procedures
• Since the Oracle JVM is embedded in the database this
introduces a number of new concepts:
– oracle.aurora.rdbms.DbmsJava.classForNameAndSchema() for
loading a class from a database schema
– The Oracle JVM uses the database memory structures to store data
– The garbage collector makes use of the call and session memory on a
per-user basis
PL/SQL vs Java Stored Procedures
• Since the Oracle JVM is embedded in the database this
introduces a number of new concepts:
– no support for JNI
– server-side JDBC driver providing access to Oracle data (using the
"jdbc:default:connection:“ connection URL)
– server-side SQLJ translator – allows embedding of SQL statements in
Java stored procedures
Writing Java Stored Procedures
Writing Java Stored Procedures
• In order to create a Java stored procedure:
o write the Java class that contains the Java procedure(s) (static
method(s) in the class)
o load the compiled Java procedure in the Oracle database using the
loadjava utility or the CREATE JAVA command
o map a PL/SQL function/procedure to the Java procedure using the
CREATE FUNCTION/PROCEDURE command
Writing Java Stored Procedures
• The loadjava utility uses the
CREATE JAVA {SOURCE | CLASS |
RESOURCE}
command to load source/class/resource files
Writing Java Stored Procedures
• Example: loading the Sample.java source file using the
orcl user:
• Example: loading the Sample.java source file using the
orcl user and compiling it:
loadjava -u orcl Sample.java
loadjava -u orcl –resolve Sample.java
Writing Java Stored Procedures
• Map the Java static function func() from the Sample
class:
CREATE OR REPLACE FUNCTION func
RETURN VARCHAR2 AS
LANGUAGE JAVA NAME
‘Sample.func() return java.lang.String';
Writing Java Stored Procedures
• Invoke the func function:
VARIABLE result VARCHAR2(20);
CALL func() INTO :result
PRINT result;
Writing Java Stored Procedures
• You can provide privileges for other users to invoke your
class(es) using the loadjava utility or the GRANT
command:
loadjava -grant usr –u orcl Sample.java
GRANT EXECUTE ON Sample TO usr;
Writing Java Stored Procedures
demo
Managing Java Stored Procedures
Managing Java Stored Procedures
• USER_OBJECTS table (OBJECT_TYPE columns is any
of JAVA SOURCE,
JAVA CLASS or JAVA RESOURCE in a valid/invalid
state)
Managing Java Stored Procedures
• JMX can be used to monitor the Oracle JVM
• The current user must be granted the JMXSERVER role
• The dbms_java.start_jmx_agent can be used to
start the JMX server for the session
Managing Java Stored Procedures
• Java stored procedures can be debugged be debugged by
a JWDP-compliant debugger
• Such as a debugger is provided by jdb and the
JDeveloper IDE
exec DBMS_DEBUG_JDWP.CONNECT_TCP('localhost', 6666);
Managing Java Stored Procedures
• Compiler options can be specified:
– in the JAVA$OPTIONS table
– via the loadjava utility
– via the DBMS_JAVA package (that creates/modifies
the JAVA$OPTIONS table)
Managing Java Stored Procedures
demo
New Features in Oracle Database 12c
New features in Oracle Database 12c
• Support for multiple JDK versions (JDK 6 by default but
JDK 7 or earlier can be specified)
• Considering multitenant databases introduced in 12c:
PDBs (pluggable databases) share the same JDK version
specified over the CDB (container database)
New features in Oracle Database 12c
• Native Oracle JVM support for JNDI
• Customizing the default java.security resource
New features in Oracle Database 12c
• Enhanced support for logging properties lookup
• Secure use of Runtime.exec
• Improved debugging support for Java Stored Procedures
(watchpoints/breakpoints)
Thank you !
Q&A

Contenu connexe

Tendances

WebLogic Scripting Tool Overview
WebLogic Scripting Tool OverviewWebLogic Scripting Tool Overview
WebLogic Scripting Tool OverviewJames Bayer
 
Java 9 Module System Introduction
Java 9 Module System IntroductionJava 9 Module System Introduction
Java 9 Module System IntroductionDan Stine
 
itft-Java evolution
itft-Java evolutionitft-Java evolution
itft-Java evolutionAtul Sehdev
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introductionvstorm83
 
Designing a play framework application
Designing a play framework applicationDesigning a play framework application
Designing a play framework applicationVulcanMinds
 
12 Things About WebLogic 12.1.3 #oow2014 #otnla15
12 Things About WebLogic 12.1.3 #oow2014 #otnla1512 Things About WebLogic 12.1.3 #oow2014 #otnla15
12 Things About WebLogic 12.1.3 #oow2014 #otnla15Frank Munz
 
Tech_Implementation of Complex ITIM Workflows
Tech_Implementation of Complex ITIM WorkflowsTech_Implementation of Complex ITIM Workflows
Tech_Implementation of Complex ITIM Workflows51 lecture
 
Oracle WebLogic Server: Remote Monitoring and Management
Oracle WebLogic Server: Remote Monitoring and ManagementOracle WebLogic Server: Remote Monitoring and Management
Oracle WebLogic Server: Remote Monitoring and ManagementRevelation Technologies
 
Learn Oracle WebLogic Server 12c Administration
Learn Oracle WebLogic Server 12c AdministrationLearn Oracle WebLogic Server 12c Administration
Learn Oracle WebLogic Server 12c AdministrationRevelation Technologies
 
Changes in WebLogic 12.1.3 Every Administrator Must Know
Changes in WebLogic 12.1.3 Every Administrator Must KnowChanges in WebLogic 12.1.3 Every Administrator Must Know
Changes in WebLogic 12.1.3 Every Administrator Must KnowBruno Borges
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and ActivatorKevin Webber
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part IPROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part ISivaSankari36
 
Pj01 2-install java and write first java program
Pj01 2-install java and write first java programPj01 2-install java and write first java program
Pj01 2-install java and write first java programSasidharaRaoMarrapu
 
[DanNotes] XPages - Beyound the Basics
[DanNotes] XPages - Beyound the Basics[DanNotes] XPages - Beyound the Basics
[DanNotes] XPages - Beyound the BasicsUlrich Krause
 

Tendances (20)

Advanced Java
Advanced JavaAdvanced Java
Advanced Java
 
WebLogic Scripting Tool Overview
WebLogic Scripting Tool OverviewWebLogic Scripting Tool Overview
WebLogic Scripting Tool Overview
 
Javantura v4 - JVM++ The GraalVM - Martin Toshev
Javantura v4 - JVM++ The GraalVM - Martin ToshevJavantura v4 - JVM++ The GraalVM - Martin Toshev
Javantura v4 - JVM++ The GraalVM - Martin Toshev
 
Java EE 8
Java EE 8Java EE 8
Java EE 8
 
Java programming and security
Java programming and securityJava programming and security
Java programming and security
 
Java 9 Module System Introduction
Java 9 Module System IntroductionJava 9 Module System Introduction
Java 9 Module System Introduction
 
itft-Java evolution
itft-Java evolutionitft-Java evolution
itft-Java evolution
 
eXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework IntroductioneXo Platform SEA - Play Framework Introduction
eXo Platform SEA - Play Framework Introduction
 
Designing a play framework application
Designing a play framework applicationDesigning a play framework application
Designing a play framework application
 
12 Things About WebLogic 12.1.3 #oow2014 #otnla15
12 Things About WebLogic 12.1.3 #oow2014 #otnla1512 Things About WebLogic 12.1.3 #oow2014 #otnla15
12 Things About WebLogic 12.1.3 #oow2014 #otnla15
 
Tech_Implementation of Complex ITIM Workflows
Tech_Implementation of Complex ITIM WorkflowsTech_Implementation of Complex ITIM Workflows
Tech_Implementation of Complex ITIM Workflows
 
Oracle WebLogic Server: Remote Monitoring and Management
Oracle WebLogic Server: Remote Monitoring and ManagementOracle WebLogic Server: Remote Monitoring and Management
Oracle WebLogic Server: Remote Monitoring and Management
 
Learn Oracle WebLogic Server 12c Administration
Learn Oracle WebLogic Server 12c AdministrationLearn Oracle WebLogic Server 12c Administration
Learn Oracle WebLogic Server 12c Administration
 
Eureka moment
Eureka momentEureka moment
Eureka moment
 
Changes in WebLogic 12.1.3 Every Administrator Must Know
Changes in WebLogic 12.1.3 Every Administrator Must KnowChanges in WebLogic 12.1.3 Every Administrator Must Know
Changes in WebLogic 12.1.3 Every Administrator Must Know
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
 
PROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part IPROGRAMMING IN JAVA -unit 5 -part I
PROGRAMMING IN JAVA -unit 5 -part I
 
Eureka moment
Eureka momentEureka moment
Eureka moment
 
Pj01 2-install java and write first java program
Pj01 2-install java and write first java programPj01 2-install java and write first java program
Pj01 2-install java and write first java program
 
[DanNotes] XPages - Beyound the Basics
[DanNotes] XPages - Beyound the Basics[DanNotes] XPages - Beyound the Basics
[DanNotes] XPages - Beyound the Basics
 

En vedette

KDB database (EPAM tech talks, Sofia, April, 2015)
KDB database (EPAM tech talks, Sofia, April, 2015)KDB database (EPAM tech talks, Sofia, April, 2015)
KDB database (EPAM tech talks, Sofia, April, 2015)Martin Toshev
 
Security Аrchitecture of Тhe Java Platform
Security Аrchitecture of Тhe Java PlatformSecurity Аrchitecture of Тhe Java Platform
Security Аrchitecture of Тhe Java PlatformMartin Toshev
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Martin Toshev
 
RxJS vs RxJava: Intro
RxJS vs RxJava: IntroRxJS vs RxJava: Intro
RxJS vs RxJava: IntroMartin Toshev
 
Security Architecture of the Java platform
Security Architecture of the Java platformSecurity Architecture of the Java platform
Security Architecture of the Java platformMartin Toshev
 
Eclipse plug in development
Eclipse plug in developmentEclipse plug in development
Eclipse plug in developmentMartin Toshev
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbmsjain.pralabh
 
Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)
Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)
Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)Martin Toshev
 
The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message BrokerMartin Toshev
 
Oracle Database 12c Attack Vectors
Oracle Database 12c Attack VectorsOracle Database 12c Attack Vectors
Oracle Database 12c Attack VectorsMartin Toshev
 
Connecting To MS SQL Server With Mulesoft (Stored Procedure To Insert data)
Connecting To MS SQL Server With Mulesoft (Stored Procedure To Insert data)Connecting To MS SQL Server With Mulesoft (Stored Procedure To Insert data)
Connecting To MS SQL Server With Mulesoft (Stored Procedure To Insert data)Jitendra Bafna
 
Is An Agile Standard Possible For Java?
Is An Agile Standard Possible For Java?Is An Agile Standard Possible For Java?
Is An Agile Standard Possible For Java?Simon Ritter
 
Real World Java 9 (QCon London)
Real World Java 9 (QCon London)Real World Java 9 (QCon London)
Real World Java 9 (QCon London)Trisha Gee
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbmsshekhar1991
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8Martin Toshev
 

En vedette (19)

KDB database (EPAM tech talks, Sofia, April, 2015)
KDB database (EPAM tech talks, Sofia, April, 2015)KDB database (EPAM tech talks, Sofia, April, 2015)
KDB database (EPAM tech talks, Sofia, April, 2015)
 
Security Аrchitecture of Тhe Java Platform
Security Аrchitecture of Тhe Java PlatformSecurity Аrchitecture of Тhe Java Platform
Security Аrchitecture of Тhe Java Platform
 
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)Modularity of The Java Platform Javaday (http://javaday.org.ua/)
Modularity of The Java Platform Javaday (http://javaday.org.ua/)
 
Modular Java
Modular JavaModular Java
Modular Java
 
RxJS vs RxJava: Intro
RxJS vs RxJava: IntroRxJS vs RxJava: Intro
RxJS vs RxJava: Intro
 
Spring RabbitMQ
Spring RabbitMQSpring RabbitMQ
Spring RabbitMQ
 
Security Architecture of the Java platform
Security Architecture of the Java platformSecurity Architecture of the Java platform
Security Architecture of the Java platform
 
Eclipse plug in development
Eclipse plug in developmentEclipse plug in development
Eclipse plug in development
 
JVM++: The Graal VM
JVM++: The Graal VMJVM++: The Graal VM
JVM++: The Graal VM
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbms
 
Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)
Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)
Security Architecture of the Java Platform (BG OUG, Plovdiv, 13.06.2015)
 
The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message Broker
 
Oracle Database 12c Attack Vectors
Oracle Database 12c Attack VectorsOracle Database 12c Attack Vectors
Oracle Database 12c Attack Vectors
 
Connecting To MS SQL Server With Mulesoft (Stored Procedure To Insert data)
Connecting To MS SQL Server With Mulesoft (Stored Procedure To Insert data)Connecting To MS SQL Server With Mulesoft (Stored Procedure To Insert data)
Connecting To MS SQL Server With Mulesoft (Stored Procedure To Insert data)
 
Is An Agile Standard Possible For Java?
Is An Agile Standard Possible For Java?Is An Agile Standard Possible For Java?
Is An Agile Standard Possible For Java?
 
Real World Java 9 (QCon London)
Real World Java 9 (QCon London)Real World Java 9 (QCon London)
Real World Java 9 (QCon London)
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Spring RabbitMQ
Spring RabbitMQSpring RabbitMQ
Spring RabbitMQ
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 

Similaire à Writing Stored Procedures in Oracle RDBMS

Similaire à Writing Stored Procedures in Oracle RDBMS (20)

13 java in oracle
13 java in oracle13 java in oracle
13 java in oracle
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
 
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.pptLecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
 
Lecture 19 dynamic web - java - part 1
Lecture 19   dynamic web - java - part 1Lecture 19   dynamic web - java - part 1
Lecture 19 dynamic web - java - part 1
 
Java in a world of containers
Java in a world of containersJava in a world of containers
Java in a world of containers
 
Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018Java in a World of Containers - DockerCon 2018
Java in a World of Containers - DockerCon 2018
 
10 jdbc
10 jdbc10 jdbc
10 jdbc
 
10 jdbc
10 jdbc10 jdbc
10 jdbc
 
Weblogic 101 for dba
Weblogic  101 for dbaWeblogic  101 for dba
Weblogic 101 for dba
 
Chap3 3 12
Chap3 3 12Chap3 3 12
Chap3 3 12
 
OOW09 Ebs Tuning Final
OOW09 Ebs Tuning FinalOOW09 Ebs Tuning Final
OOW09 Ebs Tuning Final
 
Jakarta EE Test Strategies (2022)
Jakarta EE Test Strategies (2022)Jakarta EE Test Strategies (2022)
Jakarta EE Test Strategies (2022)
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)Java Database Connectivity (JDBC)
Java Database Connectivity (JDBC)
 
Advance java1.1
Advance java1.1Advance java1.1
Advance java1.1
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 

Plus de Martin Toshev

Building highly scalable data pipelines with Apache Spark
Building highly scalable data pipelines with Apache SparkBuilding highly scalable data pipelines with Apache Spark
Building highly scalable data pipelines with Apache SparkMartin Toshev
 
Big data processing with Apache Spark and Oracle Database
Big data processing with Apache Spark and Oracle DatabaseBig data processing with Apache Spark and Oracle Database
Big data processing with Apache Spark and Oracle DatabaseMartin Toshev
 
Semantic Technology In Oracle Database 12c
Semantic Technology In Oracle Database 12cSemantic Technology In Oracle Database 12c
Semantic Technology In Oracle Database 12cMartin Toshev
 
Practical security In a modular world
Practical security In a modular worldPractical security In a modular world
Practical security In a modular worldMartin Toshev
 
Java 9 Security Enhancements in Practice
Java 9 Security Enhancements in PracticeJava 9 Security Enhancements in Practice
Java 9 Security Enhancements in PracticeMartin Toshev
 
Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Martin Toshev
 
java2days 2014: Attacking JavaEE Application Servers
java2days 2014: Attacking JavaEE Application Serversjava2days 2014: Attacking JavaEE Application Servers
java2days 2014: Attacking JavaEE Application ServersMartin Toshev
 
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....Security Architecture of the Java Platform (http://www.javaday.bg event - 14....
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....Martin Toshev
 
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Martin Toshev
 

Plus de Martin Toshev (10)

Building highly scalable data pipelines with Apache Spark
Building highly scalable data pipelines with Apache SparkBuilding highly scalable data pipelines with Apache Spark
Building highly scalable data pipelines with Apache Spark
 
Big data processing with Apache Spark and Oracle Database
Big data processing with Apache Spark and Oracle DatabaseBig data processing with Apache Spark and Oracle Database
Big data processing with Apache Spark and Oracle Database
 
Jdk 10 sneak peek
Jdk 10 sneak peekJdk 10 sneak peek
Jdk 10 sneak peek
 
Semantic Technology In Oracle Database 12c
Semantic Technology In Oracle Database 12cSemantic Technology In Oracle Database 12c
Semantic Technology In Oracle Database 12c
 
Practical security In a modular world
Practical security In a modular worldPractical security In a modular world
Practical security In a modular world
 
Java 9 Security Enhancements in Practice
Java 9 Security Enhancements in PracticeJava 9 Security Enhancements in Practice
Java 9 Security Enhancements in Practice
 
Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Concurrency Utilities in Java 8
Concurrency Utilities in Java 8
 
java2days 2014: Attacking JavaEE Application Servers
java2days 2014: Attacking JavaEE Application Serversjava2days 2014: Attacking JavaEE Application Servers
java2days 2014: Attacking JavaEE Application Servers
 
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....Security Architecture of the Java Platform (http://www.javaday.bg event - 14....
Security Architecture of the Java Platform (http://www.javaday.bg event - 14....
 
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
Modularity of the Java Platform (OSGi, Jigsaw and Penrose)
 

Dernier

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 

Dernier (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 

Writing Stored Procedures in Oracle RDBMS

  • 1. Writing Java Stored Procedures with Oracle RDBMS Martin Toshev
  • 2. Who am I Software consultant (CoffeeCupConsulting) BG JUG board member (http://jug.bg) OpenJDK and Oracle RDBMS enthusiast Twitter: @martin_fmi
  • 3.
  • 5. Agenda • PL/SQL vs Java Stored Procedures • Writing Java Stored Procedures • Managing Java Stored Procedures • New features in Oracle Database 12c
  • 6. PL/SQL vs Java Stored Procedures
  • 7. PL/SQL vs Java Stored Procedures • Both PL/SQL and Java stored procedures are executed directly on the RDBMS • Both PL/SQL and Java stored procedures can be recompiled dynamically when source code changes • Easier migration of Java stored procedures to/from the application tier
  • 8. PL/SQL vs Java Stored Procedures • The PL/SQL Virtual Machine (PVM) is the database component that executes the PL/SQL bytecode (lower lever representation of the PL/SQL code that is generated from the PL/SQL compiler) • PVM is written in C
  • 9. PL/SQL vs Java Stored Procedures • Java procedures are executed from a JVM (Java Virtual Machine) process running inside the Oracle RDBMS: Oracle DB Oracle RDBMS PL/SQL JVM Java method
  • 10. PL/SQL vs Java Stored Procedures • Since the Oracle JVM is embedded in the database this introduces a number of new concepts: – Oracle JVM process that runs within an Oracle database session – classloader that loads classes from the database – no notion of main() method – loading of system classes from the SYS schema (where they are stored)
  • 11. PL/SQL vs Java Stored Procedures • Since the Oracle JVM is embedded in the database this introduces a number of new concepts: – oracle.aurora.rdbms.DbmsJava.classForNameAndSchema() for loading a class from a database schema – The Oracle JVM uses the database memory structures to store data – The garbage collector makes use of the call and session memory on a per-user basis
  • 12. PL/SQL vs Java Stored Procedures • Since the Oracle JVM is embedded in the database this introduces a number of new concepts: – no support for JNI – server-side JDBC driver providing access to Oracle data (using the "jdbc:default:connection:“ connection URL) – server-side SQLJ translator – allows embedding of SQL statements in Java stored procedures
  • 13. Writing Java Stored Procedures
  • 14. Writing Java Stored Procedures • In order to create a Java stored procedure: o write the Java class that contains the Java procedure(s) (static method(s) in the class) o load the compiled Java procedure in the Oracle database using the loadjava utility or the CREATE JAVA command o map a PL/SQL function/procedure to the Java procedure using the CREATE FUNCTION/PROCEDURE command
  • 15. Writing Java Stored Procedures • The loadjava utility uses the CREATE JAVA {SOURCE | CLASS | RESOURCE} command to load source/class/resource files
  • 16. Writing Java Stored Procedures • Example: loading the Sample.java source file using the orcl user: • Example: loading the Sample.java source file using the orcl user and compiling it: loadjava -u orcl Sample.java loadjava -u orcl –resolve Sample.java
  • 17. Writing Java Stored Procedures • Map the Java static function func() from the Sample class: CREATE OR REPLACE FUNCTION func RETURN VARCHAR2 AS LANGUAGE JAVA NAME ‘Sample.func() return java.lang.String';
  • 18. Writing Java Stored Procedures • Invoke the func function: VARIABLE result VARCHAR2(20); CALL func() INTO :result PRINT result;
  • 19. Writing Java Stored Procedures • You can provide privileges for other users to invoke your class(es) using the loadjava utility or the GRANT command: loadjava -grant usr –u orcl Sample.java GRANT EXECUTE ON Sample TO usr;
  • 20. Writing Java Stored Procedures demo
  • 21. Managing Java Stored Procedures
  • 22. Managing Java Stored Procedures • USER_OBJECTS table (OBJECT_TYPE columns is any of JAVA SOURCE, JAVA CLASS or JAVA RESOURCE in a valid/invalid state)
  • 23. Managing Java Stored Procedures • JMX can be used to monitor the Oracle JVM • The current user must be granted the JMXSERVER role • The dbms_java.start_jmx_agent can be used to start the JMX server for the session
  • 24. Managing Java Stored Procedures • Java stored procedures can be debugged be debugged by a JWDP-compliant debugger • Such as a debugger is provided by jdb and the JDeveloper IDE exec DBMS_DEBUG_JDWP.CONNECT_TCP('localhost', 6666);
  • 25. Managing Java Stored Procedures • Compiler options can be specified: – in the JAVA$OPTIONS table – via the loadjava utility – via the DBMS_JAVA package (that creates/modifies the JAVA$OPTIONS table)
  • 26. Managing Java Stored Procedures demo
  • 27. New Features in Oracle Database 12c
  • 28. New features in Oracle Database 12c • Support for multiple JDK versions (JDK 6 by default but JDK 7 or earlier can be specified) • Considering multitenant databases introduced in 12c: PDBs (pluggable databases) share the same JDK version specified over the CDB (container database)
  • 29. New features in Oracle Database 12c • Native Oracle JVM support for JNDI • Customizing the default java.security resource
  • 30. New features in Oracle Database 12c • Enhanced support for logging properties lookup • Secure use of Runtime.exec • Improved debugging support for Java Stored Procedures (watchpoints/breakpoints)

Notes de l'éditeur

  1. The Java process runs within an Oracle database session – this is similar to how a JVM runs in a standalone OS process server-side JDBC driver is tightly integrated with the Oracle database in order to provide fast access to Oracle data - The SQLJ translator translates Java code with SQL and creates the proper Java code that executes the statements out of those SQL statements (using the server side JDBC translator)
  2. The call memory is further divided into an old and new space
  3. The Java process runs within an Oracle database session – this is similar to how a JVM runs in a standalone OS process server-side JDBC driver is tightly integrated with the Oracle database in order to provide fast access to Oracle data - The SQLJ translator translates Java code with SQL and creates the proper Java code that executes the statements out of those SQL statements (using the server side JDBC translator)
  4. You can also specify a different schema (e.g. SAMPLE) using the –schema parameter. For example: loadjava -u orcl -schema SAMPPLE Sample.java
  5. You can also specify a different schema (e.g. SAMPLE) using the –schema parameter. For example: loadjava -u orcl -schema SAMPPLE Sample.java
  6. You can also specify a different schema (e.g. SAMPLE) using the –schema parameter. For example: loadjava -u orcl -schema SAMPPLE Sample.java
  7. You can also specify a different schema (e.g. SAMPLE) using the –schema parameter. For example: loadjava -u orcl -schema SAMPPLE Sample.java
  8. You can also specify a different schema (e.g. SAMPLE) using the –schema parameter. For example: loadjava -u orcl -schema SAMPPLE Sample.java
  9. There are some prerequisites for enabling debugging for a user – the user must be granted the DEBUG ANY PROCEDURE and DEBUG CONNECT SESSION priviliges and assigned to an ACL: begin sys.DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE( host => 'localhost', ace => xs$ace_type(privilege_list => xs$name_list('jdwp'), principal_name => 'c##demo', principal_type => xs_acl.ptype_db)); end; 2) When attaching to an Eclipse IDE debugger the current session crashes
  10. There are some prerequisites for enabling debugging for a user – the user must be granted the DEBUG ANY PROCEDURE and DEBUG CONNECT SESSION priviliges and assigned to an ACL: begin sys.DBMS_NETWORK_ACL_ADMIN.APPEND_HOST_ACE( host => 'localhost', ace => xs$ace_type(privilege_list => xs$name_list('jdwp'), principal_name => 'c##demo', principal_type => xs_acl.ptype_db)); end; 2) When attaching to an Eclipse IDE debugger the current session crashes 3) Many people just use plain System.out.println() statements …