Chapter 6 SQL Language Elements
235
The NEW SQL operator performs the same operation as the new
keyword in Java code: invoke a constructor method of a Java class. The
data type of the NEW expression is a Java class, specifically the Java
class that is being constructed.
The following expression invokes the constructor method of the String
class, a member of the java.lang package.
NEW java.lang.String( ’This argument is optional’ )
This expression returns a reference to the newly-created String object,
which can be passed to a variable or column of type
java.lang.String
.
The method constructor that is being invoked determines the number
and type of arguments.
The class whose constructor method is invoked must first be installed to
the database.
$ For more information on class and instance fields and methods, see "A
Java seminar" on page 523 of the book ASA User’s Guide.
When referencing a Java field or method from within Java code, you use the
dot (.) operator. For example, to invoke the getConnection method of
the DriverManager class you use the following:
conn = DriverManager.getConnection( temp.toString() ,
_props )
There are two ways of referencing Java fields or methods from within SQL
statements. You can use either the dot operator or the >> operator.
The dot operator has the advantage that it looks like Java code, but has the
disadvantage that in SQL the dot is also used to indicate the owner, table,
and column hierarchy, so this could be confusing to read.
Using the dot operator, a name method of an object named Employee is
invoked from SQL as follows:
select Employee.name ...
The same expression could refer to a
name
column of an
Employee
table.
The >> operator is unambiguous, but does not look like what Java
programmers may expect.
Referencing fields
and methods