IDataConn interface (deprecated)
IDataConn is deprecated and is provided for backward compatibility only. New applications should use the java.sql.Connection interface from the JDBC Core API.
The IDataConn interface represents a connection to a relational data source. IDataConn provides methods for preparing a query, executing a query, identifying table(s) to work with, and closing the connection explicitly. In addition, the data connection object is used in other operations for interacting with a data source.
IDataConn is part of the Data Access Engine (DAE) service. To create an instance of the IDataConn interface, use createDataConn( ) in the AppLogic class (deprecated), as shown in the following example:.
IDataConn conn;
if((conn = createDataConn(0, GX_DA_DAD_DRIVERS.GX_DA_DRIVER_ODBC,
"CATALOG", "CATALOG", "steve", "pass7878")) == null)
. . .
Package
com.kivasoft
Methods
Related Topics
createDataConn( ) in the AppLogic class (deprecated)
getDataConn( ) in the ITable interface (deprecated)
addRow( ), deleteRow( ), and updateRow( ) in the ITable interface (deprecated)
closeConn( )
Explicitly closes the database connection.
Syntax
public int closeConn(
int dwFlags)
dwFlags.
Specify 0, or GX_DA_CLOSECONN_FLAGS.GX_DA_UNBIND_TRANS, which explicitly unbinds a physical connection from a transaction.
Usage
The Data Access Engine performs certain housekeeping tasks, such as shutdown and cleanup, automatically and intermittently. Use closeConn( ) to explicitly close a database connection and release system resources, such as when memory is low. Calling closeConn( ) breaks the virtual connection to the database and puts the physical connection back into the database connection cache.
Rules
Return Value
GXE.SUCCESS if the method succeeds.
Example
IDataConn conn;
if((conn = createDataConn(0, GX_DA_DAD_DRIVERS.GX_DA_DRIVER_ODBC,
"CATALOG", "CATALOG", "steve", "pass7878")) == null)
{
// Cannot connect - return error message
result("Failed to connect to Catalog db");
return null;
};
// Connected - return the data connection object
// used for subsequent operations on the database
return conn;
};
. . . perform database operations . . .
// Explicitly close the connection
int closeResult;
closeResult=conn.closeConn(0);
Related Topics
createDataConn( ) in the AppLogic class (deprecated)
createTrigger( )
Creates a new trigger object in the specified table.
Syntax
int createTrigger(
String pTable,
String pName,
String pCondition,
String pOptions,
String pSQLBlock);
pTable.
The table on which the trigger is defined. You can specify the name of the owner as a prefix to the table name, for example, "jim.myTable".
pName.
The name of the trigger object to create.
pCondition.
The condition that determines whether or not the SQL procedure (defined in the pSQLBlock parameter) executes. For example, you can specify that the SQL procedure executes only if a column contains a specific value:
"FOR EACH ROW WHEN(city = 'San Francisco')"
pOptions.
The row operations that determine when the trigger executes. For example, you can specify that the trigger be activated BEFORE or AFTER an INSERT, UPDATE, and/or DELETE operation:
"AFTER INSERT, UPDATE"
pSQLBlock.
The definition of the SQL block to execute when the trigger goes into effect. Refer to your database documentation for information on the SQL block format.
Usage
A trigger is a SQL procedure associated with a table. It is automatically activated when a specified row operation, such as INSERT, UPDATE, and DELETE, is issued against the table. Use createTrigger( ) to specify the table and the data modification command that should activate the trigger, and the action or actions the trigger is to take.
Tips
Return Value
GXE.SUCCESS if the method succeeds.
Example
IDataConn conn;
conn = createDataConn(0, GX_DA_DAD_DRIVERS.GX_DA_DRIVER_ODBC,
"personnelDB", "personnelDB", "sandra", "pass7878");
conn.createTrigger("employees", "ProcessNew",
"FOR EACH ROW WHEN(title='Director')",
"AFTER INSERT", "[SQL instruction here]";
conn.enableTrigger("employees", "ProcessNew");
Related Topics
disableTrigger( )
dropTrigger( )
enableTrigger( )
disableTrigger( )
Disables a trigger associated with a specified table. This feature is supported by Oracle databases only.
Syntax
public int disableTrigger(
String pTable,
String pName);
pTable.
The table in which the trigger is located.
pName.
The name of the trigger to disable.
Usage
Use disableTrigger( ) to temporarily stop a trigger from being activated. The trigger is disabled until it is enabled with enableTrigger( ). To remove a trigger from a table permanently, use dropTrigger( ).
Return Value
GXE.SUCCESS if the method succeeds.
Related Topics
createTrigger( )
dropTrigger( )
enableTrigger( )
dropTrigger( )
Removes a trigger from a specified table.
Syntax
public int dropTrigger(
String pTable,
String pName);
pTable.
The table on which the trigger is defined.
pName.
The name of the trigger to remove.
Usage
Use dropTrigger( ) to delete a trigger that is no longer required. To temporarily stop a trigger from being activated, use disableTrigger( ).
Return Value
GXE.SUCCESS if the method succeeds.
Related Topics
createTrigger( )
disableTrigger( )
enableTrigger( )
enableTrigger( )
Enables a trigger for a specified table. This feature is supported by Oracle databases only.
Syntax
public int enableTrigger(
String pTable,
String pName);
pTable.
The table on which the trigger is defined.
pName.
The name of the trigger to enable.
Usage
Use enableTrigger( ) to prepare a specified trigger for activation. Call enableTrigger( ) after you create a trigger with createTrigger( ), or to enable a trigger that was disabled with disableTrigger( ).
Return Value
GXE.SUCCESS if the method succeeds.
Related Topics
createTrigger( ); disableTrigger( )
dropTrigger( )
executeQuery( )
Executes a flat query on the data connection.
Syntax
public IResultSet executeQuery(
int dwFlags,
IQuery pQuery,
ITrans pTrans,
IValList pProps)
dwFlags.
Specifies flags used to execute this query.
The AppLogic can pass both result set buffering and either synchronous or asynchronous queries as the flags parameter, as shown in the following example:
(GX_DA_EXECUTEQUERY_FLAGS.GX_DA_EXEC_ASYNC |
GX_DA_EXECUTEQUERY_FLAGS.GX_DA_RS_BUFFERING)
pQuery.
IQuery object that contains the flat query object to execute.
pTrans.
ITrans object that contains the transaction to which this query applies, or null.
pProps.
IValList object that contains query properties, or null for no properties. After instantiating an object of the IValList interface, set any of the following properties:
If RS_BUFFERING is enabled and if the optional parameters are not specified, the global values in the registry are used instead.
Rules
Return Value
IResultSet object containing the result of the query, or null for failure (such as invalid tables or columns, or an invalid data comparison). If the result set is empty, calling getRowNumber( ) from the IResultSet interface (deprecated) returns zero.
Example 1
// Create the flat query object
IQuery qry=createQuery();
// Set up the query
qry.setTables("CTLcust");
qry.setFields("CustomerID, Customer");
qry.setWhere("Customer"+"="+String.valueOf(custId));
// Execute the query
IResultSet rs=conn.executeQuery(0, qry, null, null);
// Check for a non empty result
if((rs!=null)&&(rs.getRowNumber()>0))
return result("Sorry, this user ("+
firstName+" "+lastName+") already exists");
// Otherwise, process the result set
Example 2
// Set up result set buffering for query
IValList props;
props = GX.CreateValList();
// Turn on result set buffering
props.setValString("RS_BUFFERING", "TRUE");
// Specify the maximum number of rows to buffer
props.setValInt("RS_MAX_ROWS", 50);
IQuery qry = createQuery();
. . . define query properties . . .
// Attempt to execute query with result set buffering
IResultSet rs = conn.executeQuery(0, qry, null, props);
Related Topics
createDataConn( ) in the AppLogic class (deprecated)
IQuery interface (deprecated)
IResultSet interface (deprecated)
ITrans interface (deprecated)
IValList interface
getConnInfo( )
Returns database and user information about the current database connection.
Syntax
public IValList getConnInfo()
Usage
When the client code calls the createDataConn( ) method in the AppLogic class to create a connection between the client and the specified database, it passes the following parameters: flags, driver, datasource, database, username, and password. Once a data connection has been established, you can call getConnInfo( ) to return the datasource, database, user, and password values.
Tip
To return the driver value, use getDriver( ).
Return Value
IValList object, or null for failure.
getConnProps( )
Returns registry information about the current database connection.
Syntax
public IValList getConnProps()
Usage
Use getConnProps( ) to get database connection information that the Netscape Application Server administrator set through the Enterprise Administrator. The information is returned in an IValList object that contains the following keys and values:
The getConnProps( ) method might return other information depending on the database being used.
Applications typically use the database vendor information in conditional code that executes differently depending on the type of database.
Return Value
IValList object, or null for failure.
Related Topics
setConnProps( )
getDriver( )
Returns the identifier of the data source driver that the current database connection is using.
Syntax
public int getDriver()
Usage
When the client code calls the createDataConn( ) method in the AppLogic class to create a connection between the client and the specified database, it passes the following parameters: flags, driver, datasource, database, username, and password. Once a data connection has been established, you can call various methods in the IDataConn interface to return the values that were passed to createDataConn( ).
Call getDriver( ) to return the driver information.
Tip
To return the datasource, database, user, and password values, use getConnInfo( ).
Return Value
An int value corresponding to one of the static variables in the GX_DA_DAD_DRIVERS class.
getTable( )
Returns the table definition object for the specified table.
Syntax
public ITable getTable(
String szTable)
szTable.
Name of the table to request. This can include the schema name, for example, "jim.myTable." Do not use patterns or wildcards.
Usage
Use getTable( ) for the following reasons:
Rule
The AppLogic usually calls getTable( ) only once to obtain a table definition. Subsequent calls return a separate ITable object that represents the same table. Each AppLogic can call getTable( ) and operate on its own copy of the table definition.
Tips
Return Value
ITable object, or null for failure (such as an invalid table name).
Example
ITable table = dbConn.getTable("CTLcust");
if(table==null) return result("Can't find the table: "+"CTLcust");
// Otherwise, process the table columns
int cCustId = table.getColumnOrdinal("CustomerID");
int cFirst = table.getColumnOrdinal("FirstName");
. . .
Related Topics
ITable interface (deprecated)
createDataConn( ) in the AppLogic class (deprecated)
Val class
IValList interface
getTables( )
Returns an IValList of database tables or views that are available to the specified user.
Syntax
public IValList getTables(
String szQualifier,
String szOwner,
String szTable)
szQualifier.
Specify null. Driver-dependent.
szOwner.
Specify null, or a schema name, which returns tables for that schema.
szTable.
Table or view name with wildcards, or null for all tables. Wildcards must be in the format supported by the data source. For example, you can use search patterns using the following characters:
Usage
Use getTables( ) when the list of available tables on the data source is unknown. The AppLogic can obtain a subset of available tables by specifying wildcards in the table name.
Rules
Tip
Use methods in the IValList interface and the Val class to iterate through the table names obtained and determine which table(s) to work with. Thereafter, use to access each table.
Return Value
IValList object containing a list of table names, or null for failure (such as if none are found to match the search expression).
Related Topics
ITable interface (deprecated)
createDataConn( ) in the AppLogic class (deprecated)
IValList interface
prepareCall( )
Creates an ICallableStmt object that contains a call to a stored procedure.
Syntax
public ICallableStmt prepareCall(
int dwFlags,
IQuery pQuery,
ITrans pTrans,
IValList pProps);
dwFlags.
Specify 0.
pQuery.
The IQuery object that contains the call to a stored procedure. The stored procedure call should have been specified with the setSQL( ) method in the IQuery interface.
pTrans.
ITrans object that contains the transaction associated with this callable statement, or null for no transaction. This same ITrans object must then be passed to the execute( ) method of the ICallableStmt interface.
pProps.
Specify null.
Usage
Use prepareCall( ) to create a ICallableStmt object that contains a call to a stored procedure. After creating the callable statement, run it by calling execute( ) in the ICallableStmt interface.
Rules
Example
// Create the database connection.
IDataConn conn_rtest = createDataConn(0,
GX_DA_DAD_DRIVERS.GX_DA_DRIVER_DEFAULT,
/* Datasource name */ "ksample",
/* Database name */ "",
/* userName */ "kdemo",
/* password */ "kdemo");
//Write command to call stored procedure
String theProc = "{call myProc1(&p1, :p2)}";
IQuery myquery;
myquery = createQuery();
myquery.setSQL(theProc);
//Prepare the callable statement for execution
ICallableStmt myStmt;
myStmt = conn_rtest.prepareCall(0, myquery, null, null);
// Set parameters and run the callable statement
Return Value
ICallableStmt object, or null for failure.
Related Topics
ICallableStmt interface (deprecated)
prepareQuery( )
Prepares a flat query object for subsequent execution.
Syntax
public IPreparedQuery prepareQuery(
int dwFlags,
IQuery pQuery,
ITrans pTrans,
IValList pProps)
dwFlags.
Specify 0.
pQuery.
IQuery object that contains the query or statement to execute.
pTrans.
ITrans object that contains the transaction to which this query applies, or null. This same object must then be passed to the execute( ) method of the IPreparedQuery interface.
pProps.
Specify null.
Usage
Use prepareQuery( ) to prepare the query, then execute the prepared query using execute( ) in the IPreparedQuery interface (deprecated). An application can also use prepareQuery( ) with result set buffering to pre-fetch result set data efficiently from a back-end database.
Rule
Before calling prepareQuery( ), AppLogic must create a query by first calling createQuery( ) in the AppLogic class (deprecated) to create the IQuery object, then using methods in the IQuery interface (deprecated) to define the query.
Return Value
IPreparedQuery object, or null for failure.
Example
// Create the data connection
IDataConn conn;
conn = createDataConn(0, GX_DA_DAD_DRIVERS.GX_DA_DRIVER_DEFAULT,
"Orders", "Orders", "user", "password");
// Create the flat query and prepared query objects
IQuery qry = createQuery();
IPreparedQuery pqry;
IValList params;
params = GX.CreateValList();
// Set up the INSERT statement
qry.setSQL("INSERT INTO TABLE Products (ProductName, QuantityPerUnit)
VALUES (:name, :quant)");
// Prepare the flat query
pqry = conn.prepareQuery(0, qry, null, null);
// Specify a set of query parameters, then execute
params.setValString(":name","Chicken Dumplings");
params.setValString(":quant", "48 packages");
IResultSet rs1 = pqry.execute(0, params, null, null);
. . . process rs1. . .
// Specify different set of query parameters, then execute
params.setValString(":name", "Rice Noodles");
params.setValString(":quant", "96 packages");
IResultSet rs2 = pqry.execute(0, params, null, null);
. . . process rs2. . .
Related Topics
IPreparedQuery interface (deprecated)
IQuery interface (deprecated)
ITrans interface (deprecated)
IValList interface
createDataConn( ) in the AppLogic class (deprecated)
setConnProps( )
Specifies registry values for the current database connection.
Syntax
public int setConnProps(
IValList pProps)
pProps.
A pointer to the IValList object that contains the connection properties to set in the registry. Use the following defined key names for the connection properties:
Usage
Use setConnProps( ) to override database connection properties that the Netscape Application Server administrator set through the Enterprise Administrator. To get the current connection properties programmatically, call getConnProps( ).
Return Value
GXE.SUCCESS if the method succeeds.
Related Topics
getConnProps( )
|