You can invoke Java methods in two different ways in Adaptive Server:
Invoke Java methods directly in SQL. Directions for invoking methods in this way are presented in Chapter 3, “Using Java Classes in SQL.”
Invoke Java methods indirectly using SQLJ stored procedures and functions that provide Transact-SQL aliases for the method name. This chapter describes invoking Java methods in this way.
Whichever way you choose, you must first create your Java methods and install them in the Adaptive Server database using the installjava utility. See Chapter 2, “Preparing for and Maintaining Java in the Database,” for more information.
You can invoke Java methods in SQL by referencing them with their fully qualified Java names. Reference instances for instance methods, and either instances or classes for static methods.
You can use static methods as user-defined functions (UDFs) that return a value to the calling environment. You can use a Java static method as a UDF in stored procedures, triggers, where clauses, select statements, or anywhere that you can use a built-in SQL function.
When you call a Java method using its name, you cannot use methods that return output parameters or result sets to the calling environment. A method can manipulate the data it receives from a JDBC connection, but the method can only return the single return value declared in its definition to the calling environment.
You cannot use cross-database invocations of UDF functions.
See Chapter 3, “Using Java Classes in SQL,” for information about using Java methods in this way.
You can invoke Java methods as SQLJ functions or stored procedures. By wrapping the Java method in a SQL wrapper, you take advantage of these capabilities:
You can use SQLJ stored procedures to return result sets and output parameters to the calling environment.
You can take advantage of SQL metadata capabilities. For example, you can view a list of all stored procedures or functions in the database.
SQLJ provides a SQL name for a method, which allows you to protect the method invocation with standard SQL permissions.
Sybase SQLJ conforms to the recognized SQLJ Part 1 standard, which allows you to use Sybase SQLJ procedures and functions in conforming non-Sybase environments.
You can invoke SQLJ functions and SQLJ stored procedures across databases.
Because Adaptive Server checks datatype mapping when the SQLJ routine is created, you need not be concerned with datatype mapping when executing the routines.
You must reference static methods in a SQLJ routine; you cannot reference instance methods.
This chapter describes how you can use Java methods as SQLJ stored procedures and functions.