User's Guide
PART 3. Java in the Database
CHAPTER 17. Using Java in the Database
This section describes how columns of Java class data types fit into the standard SQL framework.
You can use any installed Java class as a data type. You must use the fully qualified name for the data type.
For example, the following CREATE TABLE statement includes a column that has columns of Java data types asademo.Name and asademo.ContactInfo. Here, Name and ContactInfo are classes within the asademo package.
CREATE TABLE jdba.customer ( id integer NOT NULL, company_name CHAR(35) NOT NULL, JName asademo.Name NOT NULL, JContactInfo asademo.ContactInfo NOT NULL, PRIMARY KEY (id) )
Unlike other SQL data types, Java data types are case sensitive. You must supply the proper case of all parts of the data type.
You can use defaults on Java columns, and Java columns can hold NULL entries.
Java columns and defaults Columns can have as default values any function of the proper data type, or any preset default. You can use any function of the proper data type (that is, of the same class as the column) as a default value for Java columns.
Java columns and NULL Java columns can allow NULL. If no default is set on a nullable column with Java data type, the column contains NULL.
If a Java value is not set, it has a Java null value. This Java null maps onto the SQL NULL, and you can use the IS NULL and IS NOT NULL search conditions against the values. For example, suppose the description of a Product Java object in a column named JProd was not set, you can query all products with non-null values for the description as follows:
SELECT * FROM product WHERE JProd>>description IS NULL
An important part of handling Java classes in tables is the use of the class constructor. Properties of the constructor are as follows:
A constructor method has the same name as the class, and has no declared data type. For example, a simple constructor for the Product class would be declared as follows:
Product () { ...constructor code here... }
If you include no constructor method in your class definition, a default method is used that is provided by the Java base object.
You can supply more than one constructor for each class, with different numbers and types of arguments. When a constructor is invoked, the one with the proper number and type of arguments is used.