Skip to Main Content
  • Questions
  • Advantage of using Java inside Database

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Kumpatla.

Asked: December 01, 2000 - 2:34 am UTC

Last updated: March 15, 2006 - 5:05 pm UTC

Version: 8.1.5

Viewed 1000+ times

You Asked

i have recently started working on Oracle 8.1.5
i was looking at new feature in 8i.
Oracle says one can publish Java objects into database.
i read through the Documentation, how to do it.
i found that to publish and utilise a Java object inside a database, we need to write a java code as other external javacode and write another pl/sql procedure to access it.

at the top level implementation of java object, i did not find any major advantage of using Java objects.
the same implementation can be handled by external Java objects also. which can also give me additional advantage of using external JVM, instead of using embeded JVM inside the database kernel which is used by Java objects inside the database.

can use pls tell me what is the major advantage of using Java objects inside database. and can u give me any senarios where this feature can be utilised.

thankx in advance
rgds
rav

and Tom said...

Well, one advantage is -- if you have java programmers and want to write some triggers -- being able to do so in java might be to your advantage.

If you have java programmers and need to supply some non-java programmers with stored procedures to access your data, you might find the fact that having java in there is good.

If you have a java program that does lots of data manipulation -- you might find that by putting it right next to the data, it works faster (no network round trips).

The advantage of having the jvm in the database is mostly about choice. You have the CHOICE of puttng the java on the client, in an application server, or in the database.

Lets say you wanted to send an email with an attachment from a trigger in the datatabase. Hard to do in PLSQL. Easy to do in Java (in fact, sun already wrote the code, just drop it in).

Lets say your trigger needs to do some complex computation to supply a default value for a column -- you have the code in java -- just drop it in.

You might find that less moving parts is sometimes a good thing as well. If everything can fit into the database and you don't have to worry about coordinating an app server with the database -- it is sometimes easier.

It is all about choice and flexibility. Some people just want to use java as their only language -- now you can.


Rating

  (6 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

java support

mo, October 22, 2002 - 12:54 pm UTC

Tom:

One DBA is saying that. Can this be true??

In Oracle 9.0.1, Oracle won't support:

CORBA;
Enterprise Java Beans (EJB);
Oracle Server Java Pages;
Oracle Servlet Engine.



Tom Kyte
October 22, 2002 - 1:08 pm UTC

they left out the important phrase


running inside of the database itself.


We support that stuff in 9iAS now, not inside the database. Eg: no more beans in the database. And they meant to say "9iR2" - it is still in there for 9iR1.


the jvm is there, will be there, won't be going anywhere.

A reader, September 09, 2004 - 9:13 pm UTC

Hi Tom,
 I am trying to run java data bean inside database(very small code ) .. I am trying to create Constructor in java stored procedure but it's giving me error.

Can you help please. Here is the code...

  1  CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Siebel_SconnAddr_delete" AS
  2  import com.siebel.data.*;
  3  import com.siebel.data.SiebelException;
  4  import java.util.*;
  5  import java.io.*;
  6  import java.sql.*;
  7  import java.math.*;
  8  import oracle.sql.*;
  9  import oracle.jdbc.driver.*;
 10  public class Siebel_SconnAddr_delete
 11  {
 12    public static SiebelDataBean siebelDataBean;
 13     Public void Siebel_SconnAddr_delete()
 14    {
 15       siebelDataBean = new SiebelDataBean();
 16       siebelDataBean.login("siebel.TCPIP.None.None://cwppd003:2320/siebelent/eMediaObjMgr_enu/siebel
 17             "sadmin", "sadmin", "enu");
 18    }
 19  public static void Siebel(oracle.sql.ARRAY p_in) throws java.sql.SQLException,IOException
 20   {
 21  try {
 22          String[] values = (String[])p_in.getArray();
 23          siebelDataBean.traceOn("d:\\sea752\\siebsrvr\\log\\abc.txt","SQL","");
 24          SiebelService myService   = siebelDataBean.getService("DeleteAddressRecord");
 25          SiebelPropertySet myInput = siebelDataBean.newPropertySet();
 26          SiebelPropertySet myOutput = siebelDataBean.newPropertySet();
 27          for( int i = 0; i < p_in.length(); i++ ) {
 28          System.out.println( "p_in["+i+"] = " + values[i] );
 29          myInput.setProperty("Id", values[i]);
 30          myService.invokeMethod("DeleteRecord",myInput,myOutput);
 31          String Out_prop = myOutput.getProperty("ErrorMsg");
 32          System.out.println( "Output ["+ values[i] +"] = " + myOutput.getProperty("ErrorMsg") );
 33          }
 34          myService.release();
 35          siebelDataBean.traceOff();
 36      }
 37         catch (SiebelException e) {
 38          System.out.println("Error#: " + e.getErrorCode());
 39          System.out.println("Error Message: " + e.getErrorMessage());
 40         }
 41      }
 42* }
SQL> /
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Siebel_SconnAddr_delete" AS
                                                *
ERROR at line 1:
ORA-29536: badly formed source: Encountered "void" at line 12, column 11.

Was expecting one of:

<IDENTIFIER> ...

"[" ...

"." ...

"(" ...



SQL> 


Thanks 

Tom Kyte
September 10, 2004 - 7:45 am UTC

Public
^

you have a capital P.

Thanks tom...

A reader, September 10, 2004 - 10:11 am UTC


A reader, September 18, 2004 - 4:52 pm UTC

Hi Tom,
We are using siebel java data bean from oracle java stored procedure to call siebel business object and business components.

I am trying to use java constructor approch in logging into siebel application. First session would initilize the constructor and create siebel session when I execute java stored procedure first time from Sql*Plus and subsequent session(stored procedure execution) will use already open connection to connect to siebel.

But looks like constructor approch is not working from java stored procrdure..(It's working from JDK)

Can you please help here?.. Thanks


CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Siebel_SconnAddr_delete" AS import com.siebel.data.*;
import com.siebel.data.SiebelException;
import java.util.*;
import java.io.*;
import java.sql.*;
import java.math.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
public class Siebel_SconnAddr_delete
{

// Login Constructor
public static SiebelDataBean siebelDataBean;
public Siebel_SconnAddr_delete() throws Exception
{
siebelDataBean = new SiebelDataBean();
siebelDataBean.login("siebel.TCPIP.None.None://lngnpvappc006v:2320/siebelom/eMediaObjMgr_enu/siebel", "CRMLOAD", "CRMLOAD", "enu");
}


public static void Siebel(oracle.sql.ARRAY p_in) throws java.sql.SQLException,IOException,java.lang.Exception
{
try {
System.out.println("before string");
String[] values = (String[])p_in.getArray();
System.out.println("after string");

if( siebelDataBean == null)
System.out.println("siebelDataBean null");

siebelDataBean.traceOn("d:\\sea752\\siebsrvr\\log\\abc.txt","SQL","");
System.out.println("Siebel string");
SiebelService myService = siebelDataBean.getService("MH DeleteAddressRecord");


SiebelPropertySet myInput = siebelDataBean.newPropertySet();
SiebelPropertySet myOutput = siebelDataBean.newPropertySet();


for( int i = 0; i < p_in.length(); i++ ) {

System.out.println( "p_in["+i+"] = " + values[i] );
myInput.setProperty("Id", values[i]);
myService.invokeMethod("DeleteRecord",myInput,myOutput);
String Out_prop = myOutput.getProperty("ErrorMsg");
System.out.println( "Output ["+ values[i] +"] = " + myOutput.getProperty("ErrorMsg") );
}

myService.release();
siebelDataBean.traceOff();

}
catch (SiebelException e) {
System.out.println("Error#: " + e.getErrorCode());
System.out.println("Error Message: " + e.getErrorMessage());
}

}
}






Tom Kyte
September 18, 2004 - 5:26 pm UTC

well, given that

a) i'm not really too much of a java programmer

b) i don't have siebel installed (imagine) :)

c) i don't know what you could possibly be meaning by the vague "is not working from java stored procrdure". It goes along with "hey, my car wouldn't start this morning, why not?"


I'll pass on this one.



net in the database?

A reader, March 15, 2006 - 9:45 am UTC

Hi Tom I didn't knew where to ask it

I found this page
</code> http://www.oracle.com/technology/pub/articles/mastering_dotnet_oracle/williams_sps.html <code>

net seems more easy to learn but I need your advice please.
if you don't have one, could you ask from other person in Oracle, about Java vs NET in the database, please.

What had in mind Oracle to enable this features on the database, thank you

I think this question is valid only for those who works on windows.

The idea was if you can't do in sql neither on pl/sql then you can use java,

But if you use windows, now you can use net in the database, do you really need to use java, for example to call operating system executables, etc. etc.

Any comment?

Tom Kyte
March 15, 2006 - 5:05 pm UTC

you can use .nyet if you like, sure.

A reader, March 16, 2006 - 8:25 am UTC

Thanks Tom

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library