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 (part 13 of SQL:1999). 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 (not to be confused with SQLJ part 0, which defined an embedding of SQL into Java, later standardized by ISO as SQL/OLB).
Example
[edit]SQL/JRT allows a Java function to be called from SQL code like this:[1]
CREATE FUNCTION sinh(v DOUBLE) RETURNS DOUBLE
LANGUAGE JAVA DETERMINISTIC NO SQL
EXTERNAL NAME 'CLASSPATH:java.lang.Math.sinh'
SELECT sinh(doublecolumn) 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.[1]
Implementations
[edit]HSQLDB implements SQL/JRT functions and procedures alongside routines written in SQL/PSM. A Java routine names a public static Java method in its EXTERNAL NAME clause; SQL arguments and return values are converted to the corresponding Java types. Functions can return scalar values or tables represented by java.sql.ResultSet objects. The database stores the routine definition in its script, while the referenced Java class must be available to the database's class loader.[1]
HSQLDB applies the same routine characteristics to SQL/JRT and SQL/PSM routines, including declarations describing whether a routine is deterministic and whether it reads or modifies SQL data. These declarations allow the database to validate where the routine may be used and to optimize calls whose results are repeatable.[1]
Java stored procedures were also implemented in Oracle's JServer (originally called the Aurora JVM), introduced with Oracle Database 8i in 1999;[2] it later became known as the Oracle JVM.[3] IBM Db2 supported Java stored procedures by 1998 using an external JVM.[4]
See also
[edit]References
[edit]- 1 2 3 4 "Chapter 9: SQL-Invoked Routines". HyperSQL User Guide. The HSQL Development Group. Retrieved 15 October 2026.
- ↑ Bulusu Lakshman (2002). Oracle & Java Development. Sams Publishing. p. 6. ISBN 978-0-672-32117-7.
- ↑ Rick Greenwald; Robert Stackowiak; Jonathan Stern (2008). Oracle Essentials: Oracle Database 11g. O'Reilly Media. p. 323. ISBN 978-0-596-51454-9.
- ↑ Don Chamberlin (1998). A Complete Guide to DB2 Universal Database. Morgan Kaufmann. p. 565. ISBN 978-1-55860-482-7.
External links
[edit]- SQL:2003 SQL/JRT draft
- SQL:2003 SQL Standard User Defined Types and Routines from the Farrago documentation