EasyManuals Logo

IBM DB2 User Manual

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #160 background imageLoading...
Page #160 background image
Related reference
“Data types that map to database data types in Java applications” on page 193
“DB2RowID interface” on page 352
Distinct types in SQLJ applications
In an SQLJ program, you can create a distinct type using the CREATE DISTINCT
TYPE statement in an executable clause.
You can also use CREATE TABLE in an executable clause to create a table that
includes a column of that type. When you retrieve data from a column of that
type, or update a column of that type, you use Java identifiers with data types that
correspond to the built-in types on which the distinct types are based.
The following example creates a distinct type that is based on an INTEGER type,
creates a table with a column of that type, inserts a row into the table, and
retrieves the row from the table:
Related reference
“Data types that map to database data types in Java applications” on page 193
CREATE TYPE (DB2 SQL Reference)
java.sql.RowId in_rowid = rowid;
java.sqlRowId out_rowid = null;
java.sql.RowId inout_rowid = rowid;
// Declare an input, output, and
// input/output ROWID parameter
...
#sql [myConnCtx] {CALL SP_ROWID(:IN in_rowid,
:OUT out_rowid,
:INOUT inout_rowid)};
// Call the stored procedure
System.out.println("Parameter values from SP_ROWID call: ");
System.out.println("Output parameter value ");
printBytes(out_rowid.getBytes());
// Use the getBytes method to
// convert the value to bytes for printing
System.out.println("Input/output parameter value ");
printBytes(inout_rowid.getBytes());
Figure 49. Example of calling a stored procedure with a ROWID parameter
String empNumVar;
int shoeSizeVar;
...
#sql [myConnCtx] {CREATE DISTINCT TYPE SHOESIZE AS INTEGER WITH COMPARISONS};
// Create distinct type
#sql [myConnCtx] {COMMIT}; // Commit the create
#sql [myConnCtx] {CREATE TABLE EMP_SHOE
(EMPNO CHAR(6), EMP_SHOE_SIZE SHOESIZE)};
// Create table using distinct type
#sql [myConnCtx] {COMMIT}; // Commit the create
#sql [myConnCtx] {INSERT INTO EMP_SHOE
VALUES('000010',6)}; // Insert a row in the table
#sql [myConnCtx] {COMMIT}; // Commit the INSERT
#sql [myConnCtx] {SELECT EMPNO, EMP_SHOE_SIZE
INTO :empNumVar, :shoeSizeVar
FROM EMP_SHOE}; // Retrieve the row
System.out.println("Employee number: " + empNumVar +
" Shoe size: " + shoeSizeVar);
Figure 50. Defining and using a distinct type
144 Application Programming Guide and Reference for Java

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM DB2 and is the answer not in the manual?

IBM DB2 Specifications

General IconGeneral
DeveloperIBM
Initial Release1983
LicenseProprietary
Written inC, C++
CategoryDatabase Management System (RDBMS)
Operating SystemLinux, Windows
Programming LanguagesC, C++
Data ModelsRelational
EditionsCommunity, Standard, Advanced
Key Featureshigh availability, scalability