Java class data types
292
id INT NOT NULL PRIMARY KEY,
mycol MyClass )
In this statement, the
MyClass
data type is a SQL data type, but is case-
sensitive, as Java is a case-sensitive language.
You can insert a Java object into a table just as you would any other row,
using the INSERT statement. Because each row is a separate instance of the
class, you must use the NEW keyword to create an instance. For example,
INSERT INTO t2
VALUES ( 1, NEW MyClass() )
In this case, MyClass() is a Java class name, not a SQL data type, and so
must be entered in the proper case.
In this example,
MyClass() has no arguments, so each row is created using
the default constructor. In general, you would supply arguments to a class to
place distinct values in each row.
If you install a class, say MySubClass, which is a subclass of MyClass,
you can insert instances of MySubClass into a column of data type
MyClass
.
Inserting Java
objects
Using subclasses