SlideShare a Scribd company logo
Writing Java Stored Procedures
with Oracle Database 12c
Martin Toshev
Who am I
Software consultant (self-employed)
BG JUG governance board member (http://jug.bg)
OpenJDK contributor
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

More Related Content

What's hot (19)

Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 Introduction
PawanMM
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Red Hat Developers
 
WebLogic Server Work Managers and Overload Protection
WebLogic Server Work Managers and Overload ProtectionWebLogic Server Work Managers and Overload Protection
WebLogic Server Work Managers and Overload Protection
James Bayer
 
weblogic perfomence tuning
weblogic perfomence tuningweblogic perfomence tuning
weblogic perfomence tuning
prathap kumar
 
Java build tool_comparison
Java build tool_comparisonJava build tool_comparison
Java build tool_comparison
Manav Prasad
 
EAP6 performance Tuning
EAP6 performance TuningEAP6 performance Tuning
EAP6 performance Tuning
Praveen Adupa
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
PawanMM
 
Weblogic 11g admin basic with screencast
Weblogic 11g admin basic with screencastWeblogic 11g admin basic with screencast
Weblogic 11g admin basic with screencast
Rajiv Gupta
 
Liquibase & Flyway @ Baltic DevOps
Liquibase & Flyway @ Baltic DevOpsLiquibase & Flyway @ Baltic DevOps
Liquibase & Flyway @ Baltic DevOps
Andrei Solntsev
 
Oracle Weblogic Server 11g: System Administration I
Oracle Weblogic Server 11g: System Administration IOracle Weblogic Server 11g: System Administration I
Oracle Weblogic Server 11g: System Administration I
Sachin Kumar
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)
Som Prakash Rai
 
JavaOne 2011 Recap
JavaOne 2011 RecapJavaOne 2011 Recap
JavaOne 2011 Recap
Jim Bethancourt
 
Life In The FastLane: Full Speed XPages
Life In The FastLane: Full Speed XPagesLife In The FastLane: Full Speed XPages
Life In The FastLane: Full Speed XPages
Ulrich Krause
 
Weblogic application server
Weblogic application serverWeblogic application server
Weblogic application server
Anuj Tomar
 
Database change management with Liquibase
Database change management with LiquibaseDatabase change management with Liquibase
Database change management with Liquibase
Jarosław Szczepankiewicz
 
Eureka moment
Eureka momentEureka moment
Eureka moment
Paul Withers
 
Java on Windows Azure (Cloud Computing Expo 2010)
Java on Windows Azure (Cloud Computing Expo 2010)Java on Windows Azure (Cloud Computing Expo 2010)
Java on Windows Azure (Cloud Computing Expo 2010)
David Chou
 
Session 42 - Struts 2 Hibernate Integration
Session 42 - Struts 2 Hibernate IntegrationSession 42 - Struts 2 Hibernate Integration
Session 42 - Struts 2 Hibernate Integration
PawanMM
 
Life in the fast lane. Full speed XPages
Life in the fast lane. Full speed XPagesLife in the fast lane. Full speed XPages
Life in the fast lane. Full speed XPages
Ulrich Krause
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 Introduction
PawanMM
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Red Hat Developers
 
WebLogic Server Work Managers and Overload Protection
WebLogic Server Work Managers and Overload ProtectionWebLogic Server Work Managers and Overload Protection
WebLogic Server Work Managers and Overload Protection
James Bayer
 
weblogic perfomence tuning
weblogic perfomence tuningweblogic perfomence tuning
weblogic perfomence tuning
prathap kumar
 
Java build tool_comparison
Java build tool_comparisonJava build tool_comparison
Java build tool_comparison
Manav Prasad
 
EAP6 performance Tuning
EAP6 performance TuningEAP6 performance Tuning
EAP6 performance Tuning
Praveen Adupa
 
Session 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOPSession 45 - Spring - Part 3 - AOP
Session 45 - Spring - Part 3 - AOP
PawanMM
 
Weblogic 11g admin basic with screencast
Weblogic 11g admin basic with screencastWeblogic 11g admin basic with screencast
Weblogic 11g admin basic with screencast
Rajiv Gupta
 
Liquibase & Flyway @ Baltic DevOps
Liquibase & Flyway @ Baltic DevOpsLiquibase & Flyway @ Baltic DevOps
Liquibase & Flyway @ Baltic DevOps
Andrei Solntsev
 
Oracle Weblogic Server 11g: System Administration I
Oracle Weblogic Server 11g: System Administration IOracle Weblogic Server 11g: System Administration I
Oracle Weblogic Server 11g: System Administration I
Sachin Kumar
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)
Som Prakash Rai
 
Life In The FastLane: Full Speed XPages
Life In The FastLane: Full Speed XPagesLife In The FastLane: Full Speed XPages
Life In The FastLane: Full Speed XPages
Ulrich Krause
 
Weblogic application server
Weblogic application serverWeblogic application server
Weblogic application server
Anuj Tomar
 
Java on Windows Azure (Cloud Computing Expo 2010)
Java on Windows Azure (Cloud Computing Expo 2010)Java on Windows Azure (Cloud Computing Expo 2010)
Java on Windows Azure (Cloud Computing Expo 2010)
David Chou
 
Session 42 - Struts 2 Hibernate Integration
Session 42 - Struts 2 Hibernate IntegrationSession 42 - Struts 2 Hibernate Integration
Session 42 - Struts 2 Hibernate Integration
PawanMM
 
Life in the fast lane. Full speed XPages
Life in the fast lane. Full speed XPagesLife in the fast lane. Full speed XPages
Life in the fast lane. Full speed XPages
Ulrich Krause
 

Viewers also liked (17)

Java ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL DevelopersJava ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL Developers
Lucas Jellema
 
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
 
Security Аrchitecture of Тhe Java Platform
Security Аrchitecture of Тhe Java PlatformSecurity Аrchitecture of Тhe Java Platform
Security Аrchitecture of Тhe Java Platform
Martin Toshev
 
Modular Java
Modular JavaModular Java
Modular Java
Martin Toshev
 
RxJS vs RxJava: Intro
RxJS vs RxJava: IntroRxJS vs RxJava: Intro
RxJS vs RxJava: Intro
Martin Toshev
 
Spring RabbitMQ
Spring RabbitMQSpring RabbitMQ
Spring RabbitMQ
Martin Toshev
 
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 Architecture of the Java platform
Security Architecture of the Java platformSecurity Architecture of the Java platform
Security Architecture of the Java platform
Martin Toshev
 
JVM++: The Graal VM
JVM++: The Graal VMJVM++: The Graal VM
JVM++: The Graal VM
Martin Toshev
 
Eclipse plug in development
Eclipse plug in developmentEclipse plug in development
Eclipse plug in development
Martin Toshev
 
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 Broker
Martin Toshev
 
Oracle Database 12c Attack Vectors
Oracle Database 12c Attack VectorsOracle Database 12c Attack Vectors
Oracle Database 12c Attack Vectors
Martin Toshev
 
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
 
Spring RabbitMQ
Spring RabbitMQSpring RabbitMQ
Spring RabbitMQ
Martin Toshev
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
Martin Toshev
 
Java ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL DevelopersJava ain't scary - introducing Java to PL/SQL Developers
Java ain't scary - introducing Java to PL/SQL Developers
Lucas Jellema
 
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
 
Security Аrchitecture of Тhe Java Platform
Security Аrchitecture of Тhe Java PlatformSecurity Аrchitecture of Тhe Java Platform
Security Аrchitecture of Тhe Java Platform
Martin Toshev
 
RxJS vs RxJava: Intro
RxJS vs RxJava: IntroRxJS vs RxJava: Intro
RxJS vs RxJava: Intro
Martin Toshev
 
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 Architecture of the Java platform
Security Architecture of the Java platformSecurity Architecture of the Java platform
Security Architecture of the Java platform
Martin Toshev
 
Eclipse plug in development
Eclipse plug in developmentEclipse plug in development
Eclipse plug in development
Martin Toshev
 
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 Broker
Martin Toshev
 
Oracle Database 12c Attack Vectors
Oracle Database 12c Attack VectorsOracle Database 12c Attack Vectors
Oracle Database 12c Attack Vectors
Martin Toshev
 
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
 
New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
Martin Toshev
 
Ad

Similar to Writing Stored Procedures with Oracle Database 12c (20)

13 java in oracle
13 java in oracle13 java in oracle
13 java in oracle
Graham Royce
 
MySQL/JVM
MySQL/JVMMySQL/JVM
MySQL/JVM
JustAnotherAbstraction
 
Oracle Database Programming Using Java And Web Services 1st Edition Kuassi Me...
Oracle Database Programming Using Java And Web Services 1st Edition Kuassi Me...Oracle Database Programming Using Java And Web Services 1st Edition Kuassi Me...
Oracle Database Programming Using Java And Web Services 1st Edition Kuassi Me...
janionkocho
 
Plsql les04
Plsql les04Plsql les04
Plsql les04
sasa_eldoby
 
Dynamic and Embedded SQL for db practices.pptx
Dynamic and Embedded SQL for db practices.pptxDynamic and Embedded SQL for db practices.pptx
Dynamic and Embedded SQL for db practices.pptx
angelinjeba6
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
kunj desai
 
Thinking Beyond ORM in JPA
Thinking Beyond ORM in JPAThinking Beyond ORM in JPA
Thinking Beyond ORM in JPA
Patrycja Wegrzynowicz
 
Concepts of NonStop SQL/MX: Part 5 - Stored Procedures
Concepts of NonStop SQL/MX: Part 5 - Stored ProceduresConcepts of NonStop SQL/MX: Part 5 - Stored Procedures
Concepts of NonStop SQL/MX: Part 5 - Stored Procedures
Frans Jongma
 
Oracle ADF Architecture TV - Design - Architecting for PLSQL Integration
Oracle ADF Architecture TV - Design - Architecting for PLSQL IntegrationOracle ADF Architecture TV - Design - Architecting for PLSQL Integration
Oracle ADF Architecture TV - Design - Architecting for PLSQL Integration
Chris Muir
 
Stored-Procedures-Presentation
Stored-Procedures-PresentationStored-Procedures-Presentation
Stored-Procedures-Presentation
Chuck Walker
 
Industrial training
Industrial trainingIndustrial training
Industrial training
SOUVIK BANERJEE
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
Graduate Project Summary
Graduate Project SummaryGraduate Project Summary
Graduate Project Summary
JustAnotherAbstraction
 
Experiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the DatabaseExperiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the Database
Marcelo Ochoa
 
App c
App cApp c
App c
daniil3
 
Presentation for java data base connectivity
Presentation for java data base connectivityPresentation for java data base connectivity
Presentation for java data base connectivity
kanjariya006
 
Database Access With JDBC
Database Access With JDBCDatabase Access With JDBC
Database Access With JDBC
Dharani Kumar Madduri
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
myrajendra
 
10 jdbc
10 jdbc10 jdbc
10 jdbc
snopteck
 
10 jdbc
10 jdbc10 jdbc
10 jdbc
snopteck
 
Oracle Database Programming Using Java And Web Services 1st Edition Kuassi Me...
Oracle Database Programming Using Java And Web Services 1st Edition Kuassi Me...Oracle Database Programming Using Java And Web Services 1st Edition Kuassi Me...
Oracle Database Programming Using Java And Web Services 1st Edition Kuassi Me...
janionkocho
 
Dynamic and Embedded SQL for db practices.pptx
Dynamic and Embedded SQL for db practices.pptxDynamic and Embedded SQL for db practices.pptx
Dynamic and Embedded SQL for db practices.pptx
angelinjeba6
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
kunj desai
 
Concepts of NonStop SQL/MX: Part 5 - Stored Procedures
Concepts of NonStop SQL/MX: Part 5 - Stored ProceduresConcepts of NonStop SQL/MX: Part 5 - Stored Procedures
Concepts of NonStop SQL/MX: Part 5 - Stored Procedures
Frans Jongma
 
Oracle ADF Architecture TV - Design - Architecting for PLSQL Integration
Oracle ADF Architecture TV - Design - Architecting for PLSQL IntegrationOracle ADF Architecture TV - Design - Architecting for PLSQL Integration
Oracle ADF Architecture TV - Design - Architecting for PLSQL Integration
Chris Muir
 
Stored-Procedures-Presentation
Stored-Procedures-PresentationStored-Procedures-Presentation
Stored-Procedures-Presentation
Chuck Walker
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
Dharita Chokshi
 
Experiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the DatabaseExperiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the Database
Marcelo Ochoa
 
Presentation for java data base connectivity
Presentation for java data base connectivityPresentation for java data base connectivity
Presentation for java data base connectivity
kanjariya006
 
Ad

More from Martin Toshev (11)

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
Martin 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 Database
Martin Toshev
 
Jdk 10 sneak peek
Jdk 10 sneak peekJdk 10 sneak peek
Jdk 10 sneak peek
Martin Toshev
 
Semantic Technology In Oracle Database 12c
Semantic Technology In Oracle Database 12cSemantic Technology In Oracle Database 12c
Semantic Technology In Oracle Database 12c
Martin Toshev
 
Practical security In a modular world
Practical security In a modular worldPractical security In a modular world
Practical security In a modular world
Martin Toshev
 
Java 9 Security Enhancements in Practice
Java 9 Security Enhancements in PracticeJava 9 Security Enhancements in Practice
Java 9 Security Enhancements in Practice
Martin Toshev
 
Java 9 sneak peek
Java 9 sneak peekJava 9 sneak peek
Java 9 sneak peek
Martin Toshev
 
Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Concurrency Utilities in Java 8
Concurrency Utilities in Java 8
Martin Toshev
 
java2days 2014: Attacking JavaEE Application Servers
java2days 2014: Attacking JavaEE Application Serversjava2days 2014: Attacking JavaEE Application Servers
java2days 2014: Attacking JavaEE Application Servers
Martin 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
 
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
Martin 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 Database
Martin Toshev
 
Semantic Technology In Oracle Database 12c
Semantic Technology In Oracle Database 12cSemantic Technology In Oracle Database 12c
Semantic Technology In Oracle Database 12c
Martin Toshev
 
Practical security In a modular world
Practical security In a modular worldPractical security In a modular world
Practical security In a modular world
Martin Toshev
 
Java 9 Security Enhancements in Practice
Java 9 Security Enhancements in PracticeJava 9 Security Enhancements in Practice
Java 9 Security Enhancements in Practice
Martin Toshev
 
Concurrency Utilities in Java 8
Concurrency Utilities in Java 8Concurrency Utilities in Java 8
Concurrency Utilities in Java 8
Martin Toshev
 
java2days 2014: Attacking JavaEE Application Servers
java2days 2014: Attacking JavaEE Application Serversjava2days 2014: Attacking JavaEE Application Servers
java2days 2014: Attacking JavaEE Application Servers
Martin 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
 

Recently uploaded (20)

Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
How to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptxHow to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | BluebashMCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
Bluebash
 
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to KnowWhat is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
SMACT Works
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0
RodrigoMori7
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
How to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptxHow to Detect Outliers in IBM SPSS Statistics.pptx
How to Detect Outliers in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | BluebashMCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
Bluebash
 
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to KnowWhat is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
SMACT Works
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training RoadblocksDown the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0
RodrigoMori7
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 

Writing Stored Procedures with Oracle Database 12c

  • 1. Writing Java Stored Procedures with Oracle Database 12c Martin Toshev
  • 2. Who am I Software consultant (self-employed) BG JUG governance board member (http://jug.bg) OpenJDK contributor
  • 3. Agenda • PL/SQL vs Java Stored Procedures • Writing Java Stored Procedures • Managing Java Stored Procedures • New features in Oracle Database 12c
  • 4. PL/SQL vs Java Stored Procedures
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. 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)
  • 9. 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
  • 10. 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
  • 11. Writing Java Stored Procedures
  • 12. 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
  • 13. Writing Java Stored Procedures • The loadjava utility uses the CREATE JAVA {SOURCE | CLASS | RESOURCE} command to load source/class/resource files
  • 14. 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
  • 15. 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';
  • 16. Writing Java Stored Procedures • Invoke the func function: VARIABLE result VARCHAR2(20); CALL func() INTO :result PRINT result;
  • 17. 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;
  • 18. Writing Java Stored Procedures demo
  • 19. Managing Java Stored Procedures
  • 20. 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)
  • 21. 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
  • 22. 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);
  • 23. 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)
  • 24. Managing Java Stored Procedures demo
  • 25. New Features in Oracle Database 12c
  • 26. 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)
  • 27. New features in Oracle Database 12c • Native Oracle JVM support for JNDI • Customizing the default java.security resource
  • 28. 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)

Editor's Notes

  • #9: 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)
  • #10: The call memory is further divided into an old and new space
  • #11: 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)
  • #14: You can also specify a different schema (e.g. SAMPLE) using the –schema parameter. For example: loadjava -u orcl -schema SAMPPLE Sample.java
  • #15: You can also specify a different schema (e.g. SAMPLE) using the –schema parameter. For example: loadjava -u orcl -schema SAMPPLE Sample.java
  • #16: You can also specify a different schema (e.g. SAMPLE) using the –schema parameter. For example: loadjava -u orcl -schema SAMPPLE Sample.java
  • #17: You can also specify a different schema (e.g. SAMPLE) using the –schema parameter. For example: loadjava -u orcl -schema SAMPPLE Sample.java
  • #18: You can also specify a different schema (e.g. SAMPLE) using the –schema parameter. For example: loadjava -u orcl -schema SAMPPLE Sample.java
  • #23: 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
  • #24: 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 …