![]() |
SQL-J Language Reference
|
Reference Manual |
CALL statementThe CALL statement executes a public method call associated with a Java class (a static method) or an object (a non-static method). The CALL statement is the only way to execute methods with void return types. The ? = syntax allows you to retrieve a return value from the method call. It is provided for use within a JDBC CallableStatement; however, it also works from a Statement or PreparedStatement. In Cloudscape, it is more typical to use the VALUES expression to retrieve a return value from a method call. The following two statements are similar:
-- this statement returns a single-column, single-row
-- this statement does not return a result set The method can return a void type or any valid Java type. If its return type is not void, the returned value is simply ignored unless the ? = syntax is used. If the ? = syntax is used, the method must return a value. To iterate a method call over a number of rows, use a SelectExpression. The CALL statements operates on only a single parameter set at a time. Syntax
[ ? = ] CALL CALL Statement UsageYou can use a CALL statement in all of the following cases:
CALL myWorkUnit(getCurrentConnection(), ?, ?) The parameters are applied at the target when CALL is applied at the target, and they are saved and sent to the source for use during the next refresh. For more information about work unit invocation, see the Cloudscape Synchronization Guide. For information on method resolution, see Method Resolution and Type Correspondence. The CALL Statement and JDBCAlthough the CALL statement works with Statements, PreparedStatements, and CallableStatements, you must use the latter if you want to use JDBC OUT or INOUT parameters. (See Chapter 6, "JDBC Reference".) Dependency SystemThe CALL statement depends on all the tables named in the Java expression, if one is used, and on all aliases used in the query. Dropping an alias invalidates a prepared CALL statement if the statement uses the alias. A DROP WORK UNIT statement invalidates a statement that uses the work unit. There is no tracking of dependencies on any Java classes referenced in the CALL statement. Modification of Java Object ParametersParameters to a CALL statement are Java objects. In embedded mode, if a Java object is passed in and modified within the method, changes to it are visible to the invoker of the method because the application and Cloudscape share the same JVM. The same holds true for any method, not just those executed with a CALL statement. This is not true when running in client/server mode because a client and a server do not share the same JVM. (To see changed values in client/server mode, use INOUT parameters as described in Chapter 6, "JDBC Reference".) Consider the following example method, which alters the value of a City object parameter: public static void alterMe(City acity) throws SQLException { acity.name = "Altered Name"; } An application creates a City object, then executes that method within a CALL statement, passing in that City object as a parameter: s = conn.createStatement(); City mycity = new City(1, "Amsterdam", "Dutch", "NL", "AMS"); /* the toString() method shows the value of the name field, which should be "Amsterdam" at this point*/ System.out.println(mycity.toString()); PreparedStatement ps = conn.prepareStatement( "CALL (CLASS JBMSTours.City).alterMe(?)"); ps.setObject(1, mycity); ps.execute(); System.out.println(mycity.toString()); Here is the output in embedded mode: Loaded the embedded JDBC driver
Here is the output in client/server mode: Loaded the client JDBC driver
In embedded mode, the value of the "name" field of the mycity variable was changed in the application's memory. In client/server mode, the value of the "name" field was not changed. |
|
![]() Cloudscape Version 3.6 For information about Cloudscape technical support, go to: www.cloudscape.com/support/.Copyright © 1998, 1999, 2000 Informix Software, Inc. All rights reserved. |