Static variables in Java-SQL classes

A Java variable that is declared static is associated with the Java class, rather than with each instance of the class. The variable is allocated once for the entire class.

For example, you might include a static variable in the Address class that specifies the recommended limit on the length of the Street field:

public class Address implements java.io.Serializable {	public static int recommendedLimit;
	public String street;
	public String zip;
// ...
}

You can specify that a static variable is final, which indicates that it is not updatable:

   public static final int recommendedLimit;

Otherwise, you can update the variable.

You reference a static variable of a Java class in SQL by qualifying the static variable with an instance of the class. For example:

declare @a Address
select @a>>recommendedLimit

If you don't have an instance of the class, you can use the following technique:

select (convert(null, Address))>>recommendedLimit

The expression “(convert(null, Address))” converts a null value to an Address type; that is, it generates a null Address instance, which you can then qualify with the static variable name. You cannot reference a static variable of a Java class in SQL by qualifying the static variable with the class name. For example, the following are both incorrect:

select Address.recommendedLimitselect Address>>recommendedLimit

Values assigned to non-final static variables are accessible only within the current session.