Previous Next Contents Index


IColumn interface (deprecated)

IColumn is deprecated and is provided for backward compatibility only. New applications should use the interfaces java.sql.DatabaseMetaData or java.sql.ResultSetMetaData from the JDBC Core API.

The IColumn interface represents a column definition in a table. IColumn provides methods for obtaining descriptive information about a table column from the database catalog, which contains the column definition. Column attributes include the column name, precision, scale, size, table, and data type.

IColumn is part of the Data Access Engine (DAE) service.

To create an instance of this interface, use one of the following methods:

The following example shows creating an IColumn object:

ITable tbl = conn.getTable("Products");

IColumn col = tbl.getColumnByOrd(1);
Package
com.kivasoft

Methods
Method
Description
getName( )
Returns the name of the column or alias.
getNullsAllowed( )
Returns true if null values are allowed in the column.
getPrecision( )
Returns the precision, which is the maximum length or maximum number of digits, of the column.
getScale( )
Returns the scale, which is the number of digits to the right of the decimal point, of the column of type double.
getSize( )
Returns the maximum length, in number of bytes, allowed for a value in this column.
getTable( )
Returns the table object in which this column exists.
getType( )
Returns the data type of the column.

Example 1
The following example shows how to iterate through a table to get the names and types of the columns:

String htmlString;

IColumn col;
ITable tbl = conn.getTable("Products");

htmlString += "<h2>Products Table</h2>";
tbl.enumColumnReset();

while ((col = tbl.enumColumns()) != null) {
htmlString += "Column Name = ";
htmlString += col.getName();
htmlString += ", Column Type = ";
htmlString += col.getType();
htmlString += "<br>";
};
return result(htmlString)
Example 2
The following example goes through all columns in a Products table and constructs an HTML string showing catalog information about each column:

ITable tbl = conn.getTable("Products");

htmlString += "<h2>Products Table:</h2>";

tbl.enumColumnReset();
IColumn col = tbl.enumColumns();
int loopcnt = 1;

while (col != null) {
htmlString += "Table Name = ";
htmlString += col.getTable().getName();
htmlString += "<br>";
htmlString += "Column Name=";
htmlString += col.getName();
htmlString += "<br>";
htmlString += ", Column Type=";
htmlString += col.getType();
htmlString += "<br>";
htmlString += "Nulls Allowed (T/F) = ";
htmlString += col.getNullsAllowed();
htmlString += "<br>";
htmlString += "Max Size = ";
htmlString += col.getSize();
htmlString += "<br>";
htmlString += "Precision = ";
htmlString += col.getPrecision();
htmlString += "<br>";

if (col.getType() == GX_DA_DATA_TYPES.GX_DA_TYPE_DOUBLE){
htmlString += "Scale = ";
htmlString += col.getScale();
htmlString += "<br>";
}
htmlString += "<br>";

col = tbl.enumColumns();
loopcnt++;
};
return result(htmlString + stdResFooter());
}
}
Related Topics
getColumn( ) or getColumnByOrd( ) in the IHierResultSet interface (deprecated)

getColumn( ), getColumnByOrd( ), or enumColumns( ) in the ITable interface (deprecated)

getColumn( ), getColumnByOrd( ), or enumColumns( ) in the IResultSet interface (deprecated)

getName( )
Returns the name of the column or alias.

Syntax
public String getName()
Usage
Use getName( ) when the name of the column is unknown and is required for subsequent operations.

Tips
Return Value
String representing the name of the column, or null for failure (such as insufficient memory).

Example
The following example shows how to iterate through a table to get the names of columns:

ITable tbl = conn.getTable("Products");

tbl.enumColumnReset();

htmlString += "<h2>Products Table:</h2>";
IColumn = tbl.enumColumns();
int loopcnt;
loopcnt = 1;

while (col != null) {
htmlString += "Column Name=";
htmlString += col.getName();
htmlString += "<br>";
col = tbl.enumColumns();
loopcnt++;
};
return result(htmlString + stdResFooter());
}
}

getNullsAllowed( )
Determines whether null values are allowed in the column.

Syntax
public boolean getNullsAllowed()
Usage
A column may require data values. Use getNullsAllowed( ) if this information is unknown to determine, for subsequent operations, whether nulls are allowed or not.

Tip
For numeric columns that allow NULLs, the value is usually zero (0) in the column if a NULL is inserted. For more information, see your database vendor's documentation.

Return Value
True if the column allows nulls, or false if the column is defined as NOT NULL (requiring data values).

Example
The following example shows how to iterate through a table and return the column names, as well as whether null values are allowed in each column:

ITable tbl = conn.getTable("Products");

tbl.enumColumnReset();

htmlString += "<h2>Products Table:</h2>";

IColumn col = tbl.enumColumns();
int loopcnt;
loopcnt = 1;

while (col != null) {
htmlString += "Column Name=";
htmlString += col.getName();
htmlString += "<br>";
htmlString += "Nulls Allowed (T/F) = ";
htmlString += col.getNullsAllowed();
htmlString += "<br>";
htmlString += "<br>";
col = tbl.enumColumns();
loopcnt++;
};
return result(htmlString + stdResFooter());
}
}

getPrecision( )
Returns the precision, which is the maximum length or maximum number of digits, of the column.

Syntax
public int getPrecision()
Usage
Use getPrecision( ) when the precision of the column is unknown and is required for subsequent operations.

Return Value
An int value representing the maximum length or maximum number of digits of the column, or zero for failure (such as the precision is unknown).

Example
The following example shows how to iterate through a table and return the column names, as well as the precision value of each column:

ITable tbl = conn.getTable("Products");

tbl.enumColumnReset();

htmlString += "<h2>Products Table:</h2>";

IColumn col = tbl.enumColumns();
int loopcnt;
loopcnt = 1;

while (col != null) {
htmlString += "Column Name=";
htmlString += col.getName();
htmlString += "<br>";
htmlString += "Precision = ";
htmlString += col.getPrecision();
htmlString += "<br>";
htmlString += "<br>";
col = tbl.enumColumns();
loopcnt++;
};
return result(htmlString + stdResFooter());
}
}
getScale( )
Returns the scale, which is the number of digits to the right of the decimal point, of a column of type double.

Syntax
public int getScale()
Usage
Use getScale( ) when the scale of the column is unknown and is required for subsequent operations.

Rules
Return Value
An int value representing the fixed number of digits to the right of the decimal point, or zero if unknown or not applicable.


getSize( )
Returns the maximum length, in number of bytes, allowed for a value in this column.

Syntax
public int getSize()
Usage
Use getSize( ) when the maximum allowable length of the column is unknown and is required for subsequent operations. Note that getSize( ) does not return the actual size of data in the column.

Rules
Return Value
An int value representing the maximum length of the column, or zero for failure.

Example
The following example shows how to iterate through a table and return the column names, as well as the maximum allowable length of each column:

ITable tbl = conn.getTable("Products");

tbl.enumColumnReset();

htmlString += "<h2>Products Table:</h2>";

IColumn col = tbl.enumColumns();
int loopcnt;
loopcnt = 1;

while (col != null) {
htmlString += "Column Name=";
htmlString += col.getName();
htmlString += "<br>";
htmlString += "Max Size = ";
htmlString += col.getSize();
htmlString += "<br>";
htmlString += "<br>";
col = tbl.enumColumns();
loopcnt++;
};
return result(htmlString + stdResFooter());
}
}

getTable( )
Returns the table object in which this column exists.

Syntax
public ITable getTable()
Usage
Use getTable( ) when the table definition of the column is unknown and is required for subsequent operations. For result set columns, this method returns a table object, which is a description of the columns in the result set.

Return Value
ITable object representing the table, or null for failure.

Example
// Walk through all columns in Products table and construct

// an HTML string showing the table name for each column
ITable tbl = conn.getTable("Products");
tbl.enumColumnReset();
htmlString += "<h2>Products Table:</h2>";
IColumn col = tbl.enumColumns();
int loopcnt;
loopcnt = 1;
while (col != null) {
htmlString += "Table Name = ";
htmlString += col.getTable().getName();
htmlString += "<br>";
htmlString += "Column Name=";
htmlString += col.getName();
htmlString += "<br>";
htmlString += "<br>";
col = tbl.enumColumns();
loopcnt++;
};
return result(htmlString + stdResFooter());
}
}
Related Topics
ITable interface (deprecated)

getType( )
Returns the data type of the column.

Syntax
public int getType()

Use getType( ) when the data type of the column is unknown and is required for subsequent operations.

Return Value
An int value corresponding to one of the static variables, listed next, in the GX_DA_DATA_TYPES class.

GX_DA_TYPE_ERROR
GX_DA_TYPE_TIME
GX_DA_TYPE_BINARY
GX_DA_TYPE_DOUBLE
GX_DA_TYPE_DATETIME
GX_DA_TYPE_LONG
GX_DA_TYPE_DATE
GX_DA_TYPE_STRING

Example
// Pulls a particular column value from the result set

private static String getColumnString(IResultSet res, String colName) {

// Input parameter error checking
if((rs==null)||(rs.getRowNumber()==0)||(colName==null)) return null;

int colOrd=rs.getColumnOrdinal(colName);
IColumn col;

if((col=rs.getColumnByOrd(colOrd))==null) return null;
String valStr=null;

// Switch type
switch(col.getType()) {
case GX_DA_DATA_TYPES.GX_DA_TYPE_STRING:
valStr = rs.getValueString(colOrd);
break;
case GX_DA_DATA_TYPES.GX_DA_TYPE_LONG:
valStr=String.valueOf(rs.getValueInt(colOrd));
break;
case GX_DA_DATA_TYPES.GX_DA_TYPE_DATE:
case GX_DA_DATA_TYPES.GX_DA_TYPE_DATETIME:
case GX_DA_DATA_TYPES.GX_DA_TYPE_TIME:
valStr = rs.getValueDateString(colOrd);
break;
case GX_DA_DATA_TYPES.GX_DA_TYPE_DOUBLE:
valStr = String.valueOf(rs.getValueDouble(colOrd));
break;
default: // Unknown type, so error out
// Fall thru to the return. Note that valStr is null;
};
return valStr;

 

© Copyright 1999 Netscape Communications Corp.