IBM DB2 Manual page 168

Table of Contents

Advertisement

public class TestEnum2
{
}
Generics
You can use generics in your Java programs to assign a type to a Java collection.
The SQLJ translator tolerates Java generic syntax. Examples of generics that you
can use in SQLJ programs are:
v A List of List objects:
v A HashMap in which the key/value pair has the String type:
v A method that takes a List with elements of any type:
Although you can use generics in SQLJ host variables, the value of doing so is
limited because the SQLJ translator cannot determine the types of those host
variables.
Enhanced for loop
The enhanced for lets you specify that a set of operations is performed on each
member of a collection or array. You can use the iterator in the enhanced for loop
in host expressions.
Example: INSERT each of the items in array names into table TAB.
String[] names = {"ABC","DEF","GHI"};
for (String n : names)
{
}
Varargs
Varargs make it easier to pass an arbitrary number of values to a method. A Vararg
in the last argument position of a method declaration indicates that the last
arguments are an array or a sequence of arguments. An SQLJ program can use the
passed arguments in host expressions.
152
Application Programming Guide and Reference for Java
public enum Color {
RED,ORANGE,YELLOW,GREEN,BLUE,INDIGO,VIOLET}
Color color = null;
switch (color) {
case RED:
System.out.println("Red is at one end of the spectrum.");
#sql[ctx] { INSERT INTO MYTABLE VALUES (:color) };
break;
case VIOLET:
System.out.println("Violet is on the other end of the spectrum.");
break;
case ORANGE:
case YELLOW:
case GREEN:
case BLUE:
case INDIGO:
System.out.println("Everything else is in the middle.");
break;
List <List<String>> strList2 = new ArrayList<List<String>>();
Map <String,String> map = new HashMap<String,String>();
public void mthd(List <?> obj) {
...
}
#sql {INSERT INTO TAB (VARCHARCOL) VALUES(:n) };

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents