How Can I Use My Own Java Classes in Databases?

The Java language is more powerful than SQL. Java is an object-oriented language, so its instructions (source code) come in the form of classes. To execute Java in a database, you write the Java instructions outside the database and compile them outside the database into compiled classes (byte code), which are binary files holding Java instructions.

Compiled classes can be called from client applications as easily and in the same way as stored procedures. Java classes can contain both information about the subject and some computational logic. For example, you could design, write, and compile Java code to create an Employees class complete with various methods that perform operations on an Employees table. You install your Java classes as objects into a database and write SQL cover functions or procedures to invoke the methods in the Java classes.

Once installed, you can execute these classes from the database server using stored procedures. For example, the following statement creates the interface to a Java procedure:

CREATE PROCEDURE MyMethod() 
EXTERNAL NAME 'JDBCExample.MyMethod()V' 
LANGUAGE JAVA;

SAP Sybase IQ facilitates a runtime environment for Java classes, not a Java development environment. You need a Java development environment, such as the Java Development Kit (JDK), to write and compile Java. You also need a Java Runtime Environment to execute Java classes.

You can use many of the classes that are part of the Java API as included in the Java Development Kit. You can also use classes created and compiled by Java developers.