Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 10.0.1 » SQL Anywhere Server - Programming » Java in the Database » Java in the database Q & A

How do I use Java and SQL together? Next Page

How do I access Java from SQL?


You can treat Java methods as stored procedures, which can be called from SQL.

You must create a stored procedure that runs your method. For example:

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

For more information, see CREATE PROCEDURE statement.

For example, the SQL function PI( * ) returns the value for pi. The Java API class java.lang.Math has a parallel field named PI returning the same value. But java.lang.Math also has a field named E that returns the base of the natural logarithms, as well as a method that computes the remainder operation on two arguments as prescribed by the IEEE 754 standard.

Other members of the Java API offer even more specialized functionality. For example, java.util.Stack generates a last-in, first-out queue that can store ordered lists; java.util.HashTable maps values to keys; and java.util.StringTokenizer breaks a string of characters into individual word units.