Deploying and Managing Apama Applications > Using the Apama Database Connector > The ADBCHelper Application Programming Interface > Examples
Examples
The code listings in this section are adapted from the api-helper-example.mon application. The actual code can be found in the Apama installation’s samples\adbc\api-helper-example directory.
Opening and closing a database and executing SQL commands

monitor ADBCHelper_Example
{
  com.apama.database.DBUtil db;

  action onload {
    db.openQuickODBC( "MySQL", "fred", "fred-123", handleError );
    db.doSQLCmd( "insert into NetworkInformation values (
        'Vodafone', 'FR', 104 );");
    db.doSQLCmd( "insert into NetworkInformation values (
        'O2', 'FR', 101 );");
    db.doSQLCmd( "insert into NetworkInformation values (
        'Three', 'FR', 102 );");
    db.doSQLCmdAck( "insert into NetworkInformation values (
        'Orange', 'FR', 103 );", 100, false);

    com.apama.database.DBAcknowledge ack;
    on com.apama.database.DBAcknowledge(ackNum = 100) : ack {
      if ack.error.length() = 0 then {
log "Action complete" at INFO;
// Other success handling code ...
      }
      else {
log "Action failed: " + ack.error at ERROR;
// Other failure handling code ...
      }
    db.close( false);
  }

  action handleError( string reason ) {
    log "DB Error: " + reason at ERROR;
  }
}
Executing SQL queries

monitor ADBCHelper_Example
{
  com.apama.database.DBUtil db;

  action onload {
    db.openQuickODBC( "DBName", "user", "password", handleError );
    db.doSQLQuery(
        "SELECT * FROM NetworkInformation", handleResult );
    db.close( false);
  }

  action handleResult( dictionary< string, string > data ) {
    log "Network: " + data[ "network" ] +
    " CountryCode: " + data[ "countrycode" ] +
    " NIC: " + data[ "networkidentificationcode" ] at INFO;
  }

  action handleError( string reason ) {
    log "DB Error: " + reason at ERROR;
  }
}
Copyright © Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its Subsidiaries and or/its Affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.