Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: A little advice on Java from within oracle?
> http://otn.oracle.com (free subscription) has tutorials with sample
> code.
> It has a hello world app and it would display in the sql+ window.
> And boy... it is slow (about a factor 10 slower than using pl/sql to
> do the same)
I wouldn't be so pessimistic about Oracle JVM performance :) Indeed, on a freshly bounced database first call to JVM takes painfully long since the JVM has to be initialized which means most of 8000+ classes have to be read, most of them have to be bound to ncomped versions (that's a lot of so's/dll's to be loaded and linked in), but then it works like a charm. We benchmarked a Base64 encoding routine implemented in Java (without ncomping) and in PL/SQL (on 8i, so without ncomping, too), and didn't see any significant difference in speed, while implementation is so much simpler in Java because you don't need to reimplement bitwise shifts for example... Another Java strong point is its networking capabilities (though you have UTL_TCP for PL/SQL and will rarely need something more subtle than this interface.)
On the other side, doing triggers or anything like that in Java is not
recommended - no matter how optimized their kprb driver is, you will
still suffer from context switching between SQL engine and Java VM
and from the need to pass data into JVM and out of it.
Besides, implementing triggers in Java is MUCH more complex than in
PL/SQL. And in no event should you try to implement any J2EE stuff in
Oracle JVM (it was just plain bad idea to put support for it into 8i and
it's the right move they dropped it from 9i.) After all, Oracle is the
RDBMS, though it has many compelling features of an application server
and I for one advocate that they should be used to full extent. Java is not
RDBMS-related or optimized language, it's general purpose language.
There's no better way to implement things in Oracle than to use PL/SQL
wherever possible (if you can't do it in plain SQL, that is.) Only resort to
Java when PL/SQL and standard packages do not provide you with the
tools you need (which is pretty rare.)
For example, you could write a simple messaging class that will implement
your messaging system, and a static wrapper class which can be interfaced
to PL/SQL. Then you write PL/SQL wrapper package for that class, exposing
its methods, and call that from your PL/SQL triggers. But don't implement
the trigger itself in Java.
As for Hello World app, it's as simple as this:
CREATE OR REPLACE JAVA SOURCE NAMED "HelloWorld"
AS
final class HelloWorld {
public static String print()
{
return "Hello, World!";
}
}
/
create or replace function JavaHelloWorld return varchar2
as
LANGUAGE JAVA NAME 'HelloWorld.print() return java.lang.String';
/
select JavaHelloWorld from sys.dual;
-- Vladimir Zakharychev (bob@dpsp-yes.com) http://www.dpsp-yes.com Dynamic PSP(tm) - the first true RAD toolkit for Oracle-based internet applications. All opinions are mine and do not necessarily go in line with those of my employer.Received on Fri Nov 15 2002 - 13:24:21 CST