Using Java classes as datatypes

After you have installed a set of Java classes, you can reference them as datatypes in SQL. To be used as a column datatype, a Java-SQL class must be defined as public and must implement either java.io.Serializable or java.io.Externalizable.

You can specify Java-SQL classes as:

When you create a table, you can specify Java-SQL classes as the datatypes of SQL columns:

create table emps (
		name varchar(30),
		home_addr Address,
		mailing_addr Address2Line null )

The name column is an ordinary SQL character string, the home_addr and mailing_addr columns can contain Java objects, and Address and Address2Line are Java-SQL classes that have been installed in the database.

You can specify Java-SQL classes as the datatypes of Transact-SQL variables:

declare @A Address
declare @A2 Address2Line

You can also specify default values for Java-SQL columns, subject to the normal constraint that the specified default must be a constant expression. This expression is normally a constructor invocation using the new operator with constant arguments, such as the following:

create table emps (
		name varchar(30),
		home_addr Address default new Address
			('Not known', ''),
		mailing_addr Address2Line
)