Migrating PL/SQL To Java Stored Procedure
Migrating PL/SQL To Java Stored Procedure
This white paper is intended to provide IT decision makers with the relevant information and considerations regarding the
migration of PL/SQL code to Java stored procedures
PL/SQL
PL/SQL is Oracle’s procedural extension to SQL. From its inception, PL/SQL has been designed and optimized for stored
procedures and functions. It is well suited for encapsulating SQL operations with procedural logic and for manipulating all
database object types.
Stored Procedures
Stored Procedures allow the processing of a set of database operations in one call. All database access must go across the
network, which, in some cases can result in poor performance. For each SQL statement, an application must initiate a
separate communication with the database. By processing data locally within the database and returning just the results,
stored procedures enhance the performance of data-intensive operations. A stored procedure is invoked through an SQL
interface, which hides their implementation from the requestor. A client application can then simply use the interface and
call the stored procedure to obtain results of the SQL statements that are contained in the procedure. In addition, stored
procedures can help to centralize business logic. If you make changes to a stored procedure, the changes are immediately
available to all client applications that use it.
Stored Procedure
Read, Insert, Update, Delete
Data
UI Database
Limitations of PL/SQL
As PL/SQL is proprietary to Oracle, code written in PLSQL is not portable across databases
PL/SQL is a procedural language and not object oriented
Requires a paid subscription or license to use
PL/SQL has limited or no functionality for interacting with the network or operating systems. For example: sending
mails, transferring data through FTP, file reading and writing operations, zipping and executing host command
line functions
Java offers support for networking, multi-threading and automated storage management techniques such as garbage
collection that makes application development easy and less error prone.
Applications are platform independent
Java uses the motto “write once, run anywhere”. This means Java code and libraries can run on any platform that supports a
Java virtual machine. This reduces the task of porting applications
Applets ORACLE
RM/IIOP Centralizing
Pc’s
Business Logic
DB2
Applets
Web
HTTP
Browsers Java Stored Procedure
HSQLDB
Applets
Pervasive RM/IIOP
Devices
JAVA DB
Prerequisite
The above program creates a Java source and a Java class object
With Oracle and other major database vendors supporting Java based procedures, it is worthwhile to move the PLSQL
code completely to a Java environment. With the advantages of portability and distributed multi-tier architecture, it is
always good to have the flexibility of deploying the core business logic of enterprise applications either in the middle-tier or
database tier. 100% percent of Java based implementation supports Windows, Solaris, Linux and other OS’s with java
virtual machine.
PLSQL code can be migrated to Java based procedures as almost all PLSQL types have their Java counterpart. Below is a
table illustrating the most commonly used ones.
VARCHAR 2 Java.lang.String
NUBMER int,long,float,double
Data types Oracle.sql.BLOB
BLOB
TIMESTAMP Oracle.sql.TIMESTAMP
Conditional IF-THEN-ELSE
IF-THEN-ELSEIF if-elseif-else
Statements
SELECT
SQL INSERT
Prepared Statements
Statements UPDATE
DELETE
Implicit Cursors
Cursors Explicit Cursors
Java.sql.ResultSet
Java.util.List
Collections Collections and Records Java.util.Map
As with the above table, PL/SQL named blocks like Stored Procedures, Functions, Triggers and Packages can also be
converted to Java code. The converted java code can be deployed in a standalone or a J2EE environment as a business
component. As Java based procedures uses JDBC API for initiating connections there is no need of any third party API.
Need for migrating from PL/SQL to Java Stored Procedure
Conclusion
A JVM integrated database that complies with the J2SE standards allows extending database features and
programmability through java stored procedures. This paper highlights the simplicity and power of Java stored procedures.
As Java is tightly integrated with the database it can seamlessly interoperate with SQL and PL/SQL. Java based procedures
offers a variety of benefits to application developers including high application throughput, less network traffic and
seamless interoperability among java, SQL and PL/SQL. In addition, because Java Stored Procedures are based on open
standards, they allow portability across several database vendors.
References
http://www2.sys-con.com/itsg/virtualcd/java/archives/0412/ashmore/index.html
http://docs.oracle.com/cd/E11882_01/java.112/e10588/chone.htm#JJDEV01000
http://docs.oracle.com/cd/E11882_01/java.112/e10588/chsix.htm#JJDEV13258
About Aspire
Aspire Systems is a global technology services firm serving as a trusted technology partner for our customers. We work
with some of the world's most innovative enterprises and independent software vendors, helping them leverage
technology and outsourcing in our specific areas of expertise. Our services include Product Engineering, Enterprise
Transformation, Independent Testing Services and IT Infrastructure Support services
Our core philosophy of "Attention. Always." communicates our belief in lavishing care and attention on our customers
and employees.
Find Us
CA , USA l London, UK l SharJah, UAE l Chennai , India
+91 - 044 - 67404000 , +1 - 908 - 218 -50
Slideshare
http://www.slideshare.net/AspireSystems www.linkedin.com/company/aspire-systems
LinkedIn htTwitter
tps://twit er.com/AspireSystems
For more info contact
[email protected] or visit www.aspiresys.com