SQL/JRT


SQL/JRT, or SQL Routines and Types for the Java Programming Language, is an extension to the SQL standard first published as ISO/IEC 9075-13:2002. SQL/JRT specifies the ability to invoke static Java methods as routines from within SQL applications, commonly referred to as "Java stored procedures". SQL/JRT also calls for the ability to use Java classes as SQL structured user-defined types. The two parts of the extension originate from the earlier ANSI SQLJ part 1 and 2 standards.

Example

SQL/JRT allows a Java function to be called from SQL code like this:

CREATE FUNCTION sinh RETURNS DOUBLE
LANGUAGE JAVA DETERMINISTIC NO SQL
EXTERNAL NAME 'CLASSPATH:java.lang.Math.sinh'
SELECT sinh FROM mytable

SQL/JRT also allows Java code to dynamically generate tables using a java.sql.ResultSet object. The result sets returned are converted to SQL tables and can be used anywhere a table or view can be used.

Implementations

SQL/JRT stored procedures are implemented in HSQLDB. Java stored procedures have also been implemented in Oracle's JServer, which was introduced in the Oracle Database version 8i in 1999; it is now called Oracle JVM. IBM DB2 also supported Java stored procedures since about 1998, although using an external JVM.